I'm using a webview in my android application, and the web address that the webview loads contains some JavaScript. Now, I just want to know if it is possible to pass in some variable values from my Java Code to my JavaScript.
Here's my code:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.map_layout);
webView = (WebView) findViewById (R.id.webview);
WebSettings webViewSettings = webView.getSettings();
webViewSettings.setJavaScriptEnabled(true);
webView.addJavascriptInterface(new transferPlaceId(), "Android");
webView.loadUrl("http://webaddress.com/directory/page.html");
}
Javascript Interface works well, no need to worry about it. Any help will be much appreciated. Thanks in advance!
Yes, you can
String name = "foo";
webView.loadUrl("javascript:functionName('"+name+"')");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.