### Scroll To Bottom of WebView

This is an example of s crolling to the bottom of a page loaded in a WebView (requires the JavaObject library).
HTML Code Index.html
<!DOCTYPE html>
<html>
<body>
<p>
Testing JavaScript to scroll within a webpage.
</p>
<hr>
<div id="content">
</div>
<hr>
</body>
</html>
B4J Code
'The WebView is defined in layoutfile main.bjl
`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
'JavaScript ScrollTo command - in this case scroll to the bottom of the page
'Syntax: window.scrollTo(xpos,ypos)
Dim jsscrollto As String = "window.scrollTo(0, document.body.scrollHeight);"
'STEP 1
'Set the content of the webpage
Dim sb As StringBuilder
sb.Initialize
For i = 0 To 100
sb.Append($"Line ${i}
"$)
Next
'Create the JavaScript
script = $"document.getElementById("${elementid}").innerHTML = '${sb.ToString}';"$
'Set the content
joWV.RunMethodJO("getEngine", Null).RunMethod("executeScript", Array As String(script))
'STEP 2
'Scroll to the bottom of the page
Dim joWV As JavaObject = WebView1
'Create the JavaScript
script = $"${jsscrollto}"$
'Run the javascript
joWV.RunMethodJO("getEngine", Null).RunMethod("executeScript", Array As String(script))
'
Log("wv_PageFinished :: End")
End Sub`

Changed: , Category: WebView, File: T6C284M2135.htm, ID: 2135