B4J Question How to get the html code of a webview object ?

CHAUVET

Member
Licensed User
Longtime User
hi,

How to get the HTML code of a web page loaded in a webview ?

The code bellow don't work because joWV is an object and html_txtarea.text wait a String value.

It's just trying to explain the expected result. But the code is bad.

B4X:
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Public zoneweb As WebView
Public html_txtarea As TextArea
End Sub

Sub zoneweb_PageFinished (Url As String)
Dim joWV As JavaObject = zoneweb
html_txtarea.Text = joWV.RunMethodJO("getEngine", Null).RunMethod("getDocument", _
Array As String("var element = document.getElementsByTagName('html')[0].innerHTML.toString();"))
End Sub

Can someone help me?
Thanks,
 
Last edited:

CHAUVET

Member
Licensed User
Longtime User
Hi Erel,

Everything is perfect.
Thank you for taking the time for me.

Where can I find documentation on JavaObject library Version 1.25 ?
 
Upvote 0

CHAUVET

Member
Licensed User
Longtime User
Hello Erel,

Thank you for the link. But I find this page last week on your website. And I did not find the information I need.

RunMethod (MethodName As String, Params() As Object) As Object
Runs the given method and returns the method return value.
MethodName - The case-sensitive method name.
Params - Method paramters (or Null).

RunMethodJO (MethodName As String, Params() As Object) As JavaObject
Similar to RunMethod. Returns a JavaObject instead of Object.

There are only a few lines.
How to find the name of other method?

Only: getDocument for RunMethod and getEngine for RunMethodJO

Are there other methods names?
Perhaps there is only that ?

Thank
 
Upvote 0

Yuls

Member
Licensed User
Longtime User
Try:
B4X:
Log(joWV.RunMethodJO("getEngine", null).RunMethod("executeScript", Array("document.getElementsByTagName('html')[0].innerHTML")))
Hi, Erel. I get an error when I try this code in B4a v11.50.

java.lang.RuntimeException: Method: getEngine not found in: android.webkit.WebView

Same code in BXJ, works.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I get an error when I try this code in B4a v11.50.
This code is for B4J Webview, not B4A. This is the B4J Forum
 
Upvote 0
Top