### Set WebView Content

This is an example of setting the content of a WebPage via JavaScript (requires the JavaObject library).
HTML Code Index.html
<!DOCTYPE html>
<html>
<title>B4J HowTo Set Content of WebPage</title>
<body>
<div id="content">
</body>
</html>
B4J Code
'The WebView is defined in layoutfile main.bjl
Region Project Attributes
`Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private WebView1 As WebView
End Sub`
`Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("main")
MainForm.Show
WebView1.LoadUrl("file:///" & File.Combine(File.DirApp, "index.html"))
End Sub`
`Sub WebView1_PageFinished (Url As String)
Log("wv_PageFinished :: Start")
'
'Assignt the webview to a JavaObject
Dim joWV As JavaObject = WebView1
'HTML Elementid to set the value
Dim elementid As String = "content"
'JavaScript to be executed
Dim script As String
'Set the content of the webpage
Dim sb As StringBuilder
sb.Initialize
For i = 0 To 99
If i Mod 5 = 0 Then sb.Append($"

### Heading

"$)
sb.Append($"Item ${i + 1}
"$)
Next
'Create the JavaScript
script = $"document.getElementById("${elementid}").innerHTML = '${sb.ToString}';"$
'Set the content
joWV.RunMethodJO("getEngine", Null).RunMethod("executeScript", Array As String(script))
'
Log("wv_PageFinished :: End")
End Sub`

Changed: , Category: WebView, File: T6C284M2136.htm, ID: 2136