2013-08-26 33 views
0

頁面已加載,但javascript不起作用!爲什麼在webview中的JavaScript不起作用?

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()); 
      } 
     } 
} 

和index.htm的是:

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

回答

相關問題