''' B4J !!!
#Region Project Attributes
#MainFormWidth: 600
#MainFormHeight: 700
#End Region
' jsbridge
' http://www.mediafire.com/file/q3x4mabuxhp8981/8_B4J2jsBRIDGE.zip/file
' see https://www.b4x.com/android/forum/threads/jscriptengine.35781/
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private wv As WebView
Private we, wvjo As JavaObject
'B4J2wv
Private TextArea1 As TextArea
Private Button1 As Button
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("B4JsBridge")
wv.LoadURL("file:///../B4X/B4JsBridge.html") 'c:/B4X/B4JsBridge.html
MainForm.Show
Wait For wv_PageFinished (Url As String)
'vw2B4J
we.InitializeNewInstance("javafx.scene.web.WebEngine",Null)
wvjo = wv
we = wvjo.RunMethod("getEngine",Null)
Dim e As Object = we.CreateEvent("javafx.event.EventHandler", "wv", False)
'how can we send msg to B4J Sub without alert() , alternative RunMethod ?
we.RunMethod("setOnAlert", Array(e))
End Sub
Sub wv_Event(MethodName As String, Args() As Object)
Log(Args(0))
Dim we1 As JavaObject = Args(0)
Log(" getSource: " & we1.RunMethod("getSource",Null))
Log(" getEventType: " & we1.RunMethod("getEventType",Null))
Dim dat As String = we1.RunMethod("getData",Null)
Log(" getData: " & dat)
TextArea1.Text = dat
End Sub
'vw2B4J end
'B4J2wv
Sub ExecuteJavaScript (wvwv As WebView, script As String) As Object
Dim jo As JavaObject = wvwv
Return jo.RunMethodJO("getEngine", Null).RunMethod("executeScript", Array(script))
End Sub
Sub Button1_Click
Dim executejs As String = TextArea1.Text
executejs = "B4J2wv(""" & executejs & """)"
Log(executejs)
ExecuteJavaScript(wv, executejs)
End Sub
'B4J2wv end
#Region B4JsBridge.html File content
#If htmlcontentWebView
<!doctype html><html lang="en-US">
<head>
<script type="text/javascript">
// B4J 'ExecuteJavaScript(WebView1, $"document.body.style.backgroundColor = '#fbd7bd'"$)
// B4J JSBridge
// B4JSub2jsWV
function B4J2wv(message){
document.getElementById("inputField").value = message;
}
// jsWV2B4JSub
function wv2B4J(){
var msg = document.getElementById("inputField").value;
alert(msg);
// how to get the message without alert
}
</script>
<style>
.tit {
color:#b69221;
font-size:300%;
margin-top:-11px;
}
body {
background-color:#fbd7bd;
}
</style></head>
<body>
<center><h1 class="tit">in WebView </h1></center>
<input id="inputField" type="text" value="">
<input onClick="wv2B4J()" type="button" value="send to B4J"/>
<!--input id="inputFieldtest" type="text" value="test">
<br><button Type="button" onClick="aaa()">Click alert</button-->
</body></html>
#End If
#End Region
#Region designer B4JsBridge.bjl
#If txttxt
WebView: wv
------
Label1:"in B4J"
TextArea1:" ", Button1: "send to WebView"
#End If
#End Region