Hello,
The code example below retrieves HTML content from WebView via three different techniques: 1.) MenuItem 2.) LongClick 3.) PageFinished. The code calls addJavascriptInterface() & executeJavascript() contained in WebViewExtras library V1.40 to accomplish this task.
For more background see http://www.b4x.com/android/forum/threads/save-webview-html-file.9400 and http://www.b4x.com/android/forum/threads/how-can-i-get-the-content-of-a-webview.11015/
'HUGE HATS OFF' to both Martin (Warwound) and Eriel for making WebViewExtras and WebView respectively available to the rest of us. Both of you have my gratitude.
Thanks guys,
Gregg
The code example below retrieves HTML content from WebView via three different techniques: 1.) MenuItem 2.) LongClick 3.) PageFinished. The code calls addJavascriptInterface() & executeJavascript() contained in WebViewExtras library V1.40 to accomplish this task.
For more background see http://www.b4x.com/android/forum/threads/save-webview-html-file.9400 and http://www.b4x.com/android/forum/threads/how-can-i-get-the-content-of-a-webview.11015/
'HUGE HATS OFF' to both Martin (Warwound) and Eriel for making WebViewExtras and WebView respectively available to the rest of us. Both of you have my gratitude.
Thanks guys,
Gregg
B4X:
'Activity module
Sub Process_Globals
End Sub
Sub Globals
Dim myInterface As WebViewExtras 'Requires WebViewExtras library
Dim WebView1 As WebView
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.AddMenuItem("Save webpage", "MenuItem")
Activity.LoadLayout("layoutMain") 'This layout contains a single WebView view
myInterface.addJavascriptInterface(WebView1, "B4A")
WebView1.LoadUrl("http://www.b4x.com/android/help/jsinterface.html")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub MenuItem_Click
Dim jsStatement As String = Javascript="B4A.CallSub('processHTML', true, document.documentElement.outerHTML)"
myInterface.executeJavascript(WebView1, jsStatement)
End Sub
Sub WebView1_LongClick
Dim jsStatement As String = "B4A.CallSub('processHTML', true, document.documentElement.outerHTML)"
myInterface.executeJavascript(WebView1, jsStatement)
End Sub
Sub WebView1_PageFinished (Url As String)
Dim jsStatement As String = "B4A.CallSub('processHTML', true, document.documentElement.outerHTML)"
myInterface.executeJavascript(WebView1, jsStatement)
End Sub
Sub processHTML(html As String)
Log(html)
End Sub