Android Question executeJavascript problem in webview

cbanks

Active Member
Licensed User
Longtime User
Why does the first section of code work, but not the second (Code is in the page finished sub)? It works (moves down to named anchor) when I don't use a variable, it doesn't work when I use a variable.

Code: Copy
Sub Activity_Create(FirstTime As Boolean)
    FlingableWebView1.LoadUrl("http://alumnihighschool.net/scriptures/bm/1_ne/1.html")
End Sub

Sub FlingableWebView1_PageFinished (url As String)
    Dim Javascript As String
    Javascript = "window.location.hash='#1: 8'"
    WebViewExtras1.executeJavascript(FlingableWebView1, Javascript)
End Sub

Code: Copy
Sub Activity_Create(FirstTime As Boolean)
    FlingableWebView1.LoadUrl("http://alumnihighschool.net/scriptures/bm/1_ne/1.html")
End Sub

Sub FlingableWebView1_PageFinished (url As String)
    TagsAnchorName = "#1: 8"
    Dim Javascript As String
    Javascript = "window.location.hash='" & TagsAnchorName & "'"
    WebViewExtras1.executeJavascript(FlingableWebView1, Javascript)
End Sub
 
Last edited:
Why does the first section of code work, but not the second? It works (moves down to named anchor) when I don't use a variable, it doesn't work when I use a variable.

Code: Copy
    Dim Javascript As String
Javascript = "window.location.hash='#1: 8'"
WebViewExtras1.executeJavascript(FlingableWebView1, Javascript)

Code: Copy
TagsAnchorName = "#1: 8"
Dim Javascript As String
Javascript = "window.location.hash='" & TagsAnchorName & "'"
WebViewExtras1.executeJavascript(FlingableWebView1, Javascript)


I'm the only one that don't knows Javascript !
I try to guess: some characters need to be preceded by "\" (in your TagsAnchorName)
 
Upvote 0
i would try it with
Javascript = "window.location.hash='#1: 8\'"

The ' is an special char which has to be escaped.

But i dont know wheter
#1: 8'
is an allowed anchor-name.

I would suggest to rename the anchorname to just chars and numbers (NOT beginning with a number)

->> #anchorname1

With such a name you would have less problems. btw: spaces are not allowed in anchors
 
Upvote 0
Thanks for all your help! I got it working by only including the numbers as variables.
 
Upvote 0
Back
Top