【问题标题】:goto page javascript not working in android转到页面javascript在android中不起作用
【发布时间】:2013-08-19 18:48:34
【问题描述】:

我在 Dreamweaver 中使用 html5、css3、javascript、Phonegap 创建 webapp。 我正在使用下面的代码来执行转到页面功能。它将打开一个 html 页面。但我的问题是它在android应用程序中不起作用。有什么帮助吗?

javascript代码

function gotopage(id){
var num = document.getElementById(id).value;

var jarry = ["pagenotfound.html","ch1/1.html","ch1/2.html","ch1/3.html","ch1/4.html","ch1/5.html","ch1/6.html"];
if(jarry[num] == null)
    num = 0;

window.location.href = window.location.pathname.substring(0,window.location.pathname.substring(1).indexOf("/"))+jarry[num];
//window.location.href = "/"+jarry[num];    

HTML代码

<input type="text" id="t1" size="4px"/>
<input type="button" value="Goto Page" onClick="gotopage('t1')"/>

我在 android 上收到错误消息“应用程序错误:发生网络错误。(file:///android_asset/ch1/1.html)

【问题讨论】:

  • 看起来window.location.pathname 不像你想象的那样

标签: javascript cordova goto android-assets


【解决方案1】:

建议您只使用一个 index.html 文件来构建您的 phonegap 应用程序。而不是拥有多个 html 页面。这样做的原因是您每次进入新页面时都必须调用 Cordova。这可以减慢速度。然而,拥有一个包含 1000 行 HTML 代码的文件已成为一个乏味的过程。因此,儿童浏览器插件旨在让您导航到页面以及查看非基于 Web 的文件,例如 PDF 文件和其他类型的文件。话虽如此,在您的代码中更改以下内容。

document.getElementById(id).value;

document.getElementById(id).innerHTML;

【讨论】:

    【解决方案2】:

    试试这个。

      document.getElementById(id).innerHTML;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-19
      • 2011-07-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多