B4J Question WebView GoBack/GoForward

ThRuST

Well-Known Member
Licensed User
Longtime User
Is there no GoBack and GoForward available for the WebView control in B4J? How to access it?
I want to bind these functions to buttons. Thanks
 

Daestrum

Expert
Licensed User
Longtime User
Have a look at WebEngine.getHistory()
You can then go back and forward through the entries.
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
Hi Daestrum,
you mean something like this?

B4X:
Dim Web As JavaObject = WebView1
Log(Web.RunMethodJO("getEngine", Null).RunMethod("executeScript", Array As String("GoBack;")))
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
I found it :)


B4X:
Private we As JavaObject

Sub BackButton_MouseClicked (EventData As MouseEvent)
    we.RunMethod("executeScript",Array As Object("history.back()"))
End Sub

Sub forwardButton_MouseClicked (EventData As MouseEvent)
    we.RunMethod("executeScript",Array As Object("history.forward()"))
End Sub
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
Sorry that didn't work so I tried

B4X:
Dim We As JavaObject = WebView1
    We.RunMethod("executeScript",Array As Object("history.back()"))

But that didn't work either so I'll keep trying until it works. An odd habbit that are known to many :)
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
Sorry that I messed things up, but here's a working solution

B4X:
Public we, tp As JavaObject

' Init
we.InitializeNewInstance("javafx.scene.web.WebEngine",Null)
    tp = WebView1
    we = tp.RunMethod("getEngine",Null)

' Use with
Sub BackButton_MouseClicked (EventData As MouseEvent)
    we.RunMethod("executeScript",Array As Object("history.back()"))
End Sub

Sub forwardButton_MouseClicked (EventData As MouseEvent)
    we.RunMethod("executeScript",Array As Object("history.forward()"))
End Sub

I modified Daestrums code a bit to easily get you started who are looking for a quick solution. This should work. I hope it will be useful! Thanks
 
Upvote 0
Top