Android Question ( Solved ) Get Webpage Title with WebViewExtras Ver2

mangojack

Expert
Licensed User
Longtime User
I can successfully get webpage Title with WebViewExtras lib v1.4
B4X:
Sub Activity_Create(FirstTime As Boolean)
   WebView1.Initialize("WebView1")   
   WebViewExtras1.addJavascriptInterface(WebView1, "B4A")
   '.....................
End Sub

Sub WebView1_PageFinished (Url As String)
  WebViewExtras1.executeJavascript(WebView1, "B4A.CallSub('JavascriptCallback', true, document.title)")
End Sub

Sub JavascriptCallback(String1 As String)
   Log(String1) ' = webpage title ..
End Sub

But I am having difficulties doing the same with WebViewExtras 2. The JavaCallback Sub is not fired.
lib ver2 WebViewExtras.executeJavascript method only calls for a single parameter (Javascript AS String)

I have tried ...
B4X:
WebViewExtras1.executeJavascript("B4A.CallSub('JavascriptCallback', true, document.title)")

No errors are logged .. just do not get any result from JavascriptCallback Sub.

Any help appreciated .. Thanks
 

mangojack

Expert
Licensed User
Longtime User
Erels suggestion of Little Webview Extension / WebViewXtender worked well and was able to get webpage title very easily (Thanks @Roeschti)
I needed Warwounds WebViewExtras2 lib for other purposes ( Thanks @warwound )... so rather than have the 2 libraries ,kept searching.
The folowing retieves webpage title using WebViewExtras 2 lib.

B4X:
WebView1.Initialize("WebView1")
WebViewExtras1.Initialize(WebView1)
 
Dim JavascriptInterface1 As DefaultJavascriptInterface
JavascriptInterface1.Initialize
WebViewExtras1.addJavascriptInterface(JavascriptInterface1, "B4A")
   
Activity.AddView(WebView1, 0, 0, 100%x, 100%y)
WebView1.LoadUrl("https://www.b4x.com/android/forum/forums/questions.26/")
 
Sub WebView1_PageFinished (Url As String)
  WebViewExtras1.executeJavascript("B4A.CallSub('JavascriptCallback', true, document.title)") 
End Sub

Sub JavascriptCallback(title As String)
   Log("web page title =  " & title)
End Sub
 
Upvote 0
Top