【问题标题】:Android load html file with javascript in webview getting Uncaught ReferenceErrorAndroid在webview中使用javascript加载html文件得到Uncaught ReferenceError
【发布时间】:2012-09-05 10:09:46
【问题描述】:

我正在尝试将 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));

请告诉我哪里出错了。

【问题讨论】:

    标签: javascript android webview


    【解决方案1】:

    看来问题出在评论标签上。因此,在删除此 &lt;!----&gt;// 标签后,它就起作用了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      • 2014-04-11
      • 1970-01-01
      • 2014-01-19
      • 2014-02-28
      • 1970-01-01
      • 2014-01-27
      相关资源
      最近更新 更多