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());
Comments
Post a Comment