简体   繁体   中英

Basics on javascript for android

I need to access a site through my app (Webview) .

Now the problem is I can accerss it though thats not exactly my intention . I need the application to automatically click on a button inside the webpage as soon as the user clicks on a button on the android app .

Setting up the android side is pretty well easy , but the point is how do I link the user click to the website click .

What all info do I need to know about this.

As I said , not at all good in javascript ... so will need real good help here.

Thanks in advance

To call a javascript function from android webview use

myWebView.loadUrl("javascript:myFun()");

And make a function in javascript that clicks the button

function myFun() {
  var myButton = document.getElementById('myButtonId');
  myButton.click();
}

Don't forget to enable javascript on the WebView

myWebView.getSettings().setJavaScriptEnabled(true);

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM