【发布时间】:2017-05-26 03:44:12
【问题描述】:
我想从 Android Asset 文件夹加载具有 JS 引用的 HTML 文件。当我在浏览器中打开 HTML 文件时,它会正确加载所有 JS 引用。但是当我从 Android 加载时,JS 文件并没有引用。
示例代码
WebView web_view = FindViewById<WebView>(Resource.Id.webView); `web_view.Settings.JavaScriptEnabled = true;`
string sampleHtmlData = "<html><head>" +
"<script src=\"epub.min.js\"></script>" +
"<script src=\"jquery-1.10.2.min.js\" type=\"text/javascript\"></script>" +
"<script>" +
"var book = ePub(\"Azure_Cosmos_DB_and_DocumentDB_Succinctly/\");" +
"$(document).ready(function(){ book.renderTo(\"area\"); });" +
"</script>" +
"</head><body> <div id=\"prev\" onclick=\"book.prevPage()\" style=\"font - size: 64px; cursor: pointer;\" class=\"arrow\">‹</div>" +
"<div id =\"area\" style =\"height:500px;\" ></ div >" +
"<div id = \"next\" onclick = \"book.nextPage()\" style = \"font-size: 64px;cursor:pointer;\" class=\"arrow\">›</div></body></html>";
web_view.LoadDataWithBaseURL("file:///android_asset/Sample/", sampleHtmlData, "text/html", "UTF-8", null);
我也尝试使用 LoadUrl 加载。
web_view.LoadUrl("file:///android_asset/Sample/index.html")
文件路径: 资产/样本
谁能建议我用相应的 JS 文件加载本地 Html 文件? Android 会支持 EPUB js 吗?
【问题讨论】:
-
您可能还需要设置
web_view.setDomStorageEnabled = true;。 -
我也启用了 DomStorage。还是不能给JS。 HTML 文件正在加载。但是对应的 JS 代码不起作用。我指的是 Epub.js 并使用 epub 方法来加载 epub 文件