簡體   English   中英

Android在webview中使用javascript加載html文件獲取未捕獲的ReferenceError

[英]Android load html file with javascript in webview getting Uncaught ReferenceError

我正在嘗試將html文件加載到從服務器下載的Webview中。 html文件包含javascript,並保存在應用程序緩存文件夾中。 Webview僅顯示空白屏幕,並且在日志中我看到此錯誤。

Uncaught ReferenceError: refresh_rates is not defined at file:///data/data/com.app.package/files/aboutus.html:1

HTML文件來源:

<html>
<head>
<style type="text/css">
<!--
body { margin: 0px 0px 0px 0px; }
-->
</style>
<script>
<!--
var intervalID;  

function setUpdateRates()  
{  
  refresh_rates ();
  intervalID = setInterval(refresh_rates, 50000);  
}  

function refresh_rates () {
  var url ='http://www.google.com';

  //alert(url);
  document.getElementById('rates').src = url;
}
-->
</script>
</head>

<body onload="setUpdateRates();">
<iframe name="rates" id="rates"  src="" width="100%" height="100%" frameborder="0" marginwidth="0" marginheight="0" scrolling="auto"></iframe>
</body>
</html>

網頁瀏覽:

mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setDomStorageEnabled(true);
mWebView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);

在Webview中加載html文件:

mWebView.loadUrl(mFileLoader.getFilePath(CACHE_HTML));

請讓我知道我要去哪里錯了。

看來問題出在注釋標簽上。 因此,刪除此<!---->//標記后,它就起作用了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM