0
我有一個html文件,看起來像這樣的Android的WebView和執行JavaScript
<html>
<head>
This is a test
<script>
function testingConsole() {
console.log("Reached end of Body");
}
</script>
</head>
<body>
<script type="text/javascript">testingConsole();</script>
</body>
</html>
而且我的代碼看起來像這樣
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.chart);
webView = (WebView) findViewById(R.id.wvChart);
webView.loadUrl("file:///android_asset/Chart/chart.html");
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.setWebChromeClient(new WebChromeClient());
webView.loadUrl("javascript:testingConsole();");
}
HTML文件加載罰款和文本「這是一個測試「顯示在我的WebView中。和腳本testingConsole();由於它應該是自HTML文件調用它自己執行。但是當我從我的代碼中調用它時,出現錯誤「Uncaught ReferenceError:testingConsole未定義爲null:1」
我做了一個更快的臨時版本,當我知道裝入的html時,我點擊了一個按鈕就執行了javascript,它可以工作!謝啦! – girly
它將頁面加載到循環中! –