B4J Question Webview get result from click on a link

TomDuncan

Active Member
Licensed User
Hi All,
I have a app that generates a web page locally.
I have Links inside this which I need too trigger events.
Can I find when a link has been pressed.
I have tested LocationChanged but no luck.
I just need to put in my own value in the href= area.
Then get this value
i.e.
B4X:
<a href="$COMMENT$">comment</a><br>
Tom
 

TomDuncan

Active Member
Licensed User
On my testing it was not raised.
But maybe because it is not a valid place to go to.
Will check if I can put in a marker on the page to jump to.
Tom
 

TomDuncan

Active Member
Licensed User
Just did some more tests.
I added an anchor to send to the top of the file.
Any nothing works.
This web view uses LoadHtml( MY BUILT HTML FILE)

Is this an error with Loadhtml?

Tom
 

Erel

Administrator
Staff member
Licensed User
Check this example:
B4X:
Sub Process_Globals
   Private fx As JFX
   Private MainForm As Form
   Private wv As WebView
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.Show
   wv.Initialize("wv")
   MainForm.RootPane.AddNode(wv, 10, 10, 300, 300)
   wv.LoadHtml($"<a href="http://www.example.com">link</a>"$)
End Sub

Sub wv_LocationChanged (Location As String)
   Log(Location)
   wv.LoadHtml($"<a href="http://www.example.com">link</a>"$)
End Sub
 

TomDuncan

Active Member
Licensed User
Yep, that works.

The only difference with mine in that I have created the string then pass
That string to the loadhtml
What is the $ top and tail of the string.
I am still a newbie.

Tom
 

TomDuncan

Active Member
Licensed User
Oops. Yes i did and it works.
Only as a link to a http not as an anchor.
So when I reload the page it reloads from the top.

Will I have to get the position before the action happens then move the cursor
To the old location.

Tom
 
Top