B4J Question how can if realize if webview is fully loaded

palang

Member
Licensed User
Hi, im try to write some scrapping bot via handy b4j
i have a small problem, i can not find how to realize if webview is fully loaded
i do a lot of search and i found a lots of code for b4a but nothing for b4j
i know both of them are somehow same but i dont know how to use b4a code inside b4j
is there any technique ? or they are different
 

Daestrum

Expert
Licensed User
Longtime User
You can add a changelistener to the loadworker state.

for example (uses JavaObject library)
B4X:
 Private fx As JFX
 Private MainForm As Form
 Dim wv As WebView
 Dim engine As JavaObject
 Dim loaded As Object
End Sub
Sub AppStart (Form1 As Form, Args() As String)
 MainForm = Form1
 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
 MainForm.Show
' initialize the webview (not needed if from designer)
 wv.Initialize("wv")

' get the web engine from the webview
 engine = asJO(wv).RunMethodJO("getEngine",Null)

' create the event
 loaded = engine.CreateEvent("javafx.beans.value.ChangeListener","pageLoaded",Null)

' add the event to the loadworker state 
engine.RunMethodJO("getLoadWorker",Null).RunMethodJO("stateProperty",Null).RunMethod("addListener",Array(loaded)) 

' add webview to mainform etc & get a page 
MainForm.RootPane.AddNode(wv,10,10,400,400)
 wv.LoadUrl("http://www.google.co.uk")
End Sub

Sub pageLoaded_Event (MethodName As String, Args() As Object) As Object
 Dim state As String = Args(2)  ' args(2) contains the info we want
 If state.EqualsIgnoreCase("succeeded") Then
  Log("page loaded") 
 End If
 Return Null
End Sub 
' just for creating javaobjects from existing objects
Sub asJO(o As JavaObject) As JavaObject
 Return o
End Sub
 
Upvote 0
Top