android - why javascript in webview does not work? -


page loaded javascript not work!

  protected void oncreate(bundle savedinstancestate) {             super.oncreate(savedinstancestate);             setcontentview(r.layout.activity_poll);              device.webviewshowpoll = (webview) findviewbyid(r.id.webviewshowpoll);              device.webviewshowpoll.getsettings().setjavascriptenabled(true);              //device.webviewshowpoll.getsettings().setpluginsenabled(true);             device.webviewshowpoll.getsettings().setjavascriptenabled(true);             device.webviewshowpoll.getsettings().setpluginstate(pluginstate.on);             device.webviewshowpoll.getsettings().setjavascriptcanopenwindowsautomatically(true);             device.webviewshowpoll.getsettings().setallowfileaccess(true);             device.webviewshowpoll.addjavascriptinterface(appconnector, "appconnectr");              try             {                 device.webviewshowpoll.loaddatawithbaseurl("file:///android_asset/",                         utility.convertstreamtostring(getassets().open("index.htm",                                 assetmanager.access_buffer)), "text/html", "utf-8","");              }              catch (ioexception e)             {                 log.e(getstring(r.string.app_name), e.getmessage());             }         } } 

and index.htm :

<html> <head> <script type="text/javascript"> alert('hello world!'); </script> </head> <body> <p>hello world!</p> <p>hello world!</p> </body> </html> 

you haven't set webchromeclient handle js alerts

device.webviewshowpoll.setwebchromeclient(new webchromeclient()); 

javascript alert not working in android webview


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -