0

page loaded but javascript does 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 is :

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

1 回答 1

1

您尚未设置 WebChromeClient 来处理 JS 警报

Device.webViewShowPoll.setWebChromeClient(new WebChromeClient());

JavaScript 警报在 Android WebView 中不起作用

于 2013-08-26T11:26:36.253 回答