Android Question Help with Javascript 2 (too)

Wien.Mart

Member
Licensed User
Longtime User
I have a problem with passing variables to javascript.js files. I am able to load the .js files as there are examples available. The .js files have functions in them, like uname, pwd and svrname functions. For the .js to work, I need to pass value to them. The server name is more like a url to connect to. How do I do that? Please help me. Thanks in advance.

Function like:
SendReceive(Server, UserId)

Read(Server, UserId)
 
Last edited:

warwound

Expert
Licensed User
Longtime User
Assuming that you're loading these javascript files along with a webpage in a WebView you can execute javascript using the WebView LoadUrl method:

B4X:
Dim Javascript As String
Dim Server As String="Some value"
Dim UserId As String="Some value"
Javascript="javascript:SendReceive('"&Server&"', '"&UserId&"')"
Log(Javascript)
MyWebView.LoadUrl(Javascript)

You ideally want to only execute such javascript after the webpage has loaded so add a sub to your project that listens for the WebView PageFinished (Url As String) event and execute the javascript after that event has been raised.

Martin.
 
Upvote 0
Top