【问题标题】:Changing page using Javascript使用 Javascript 更改页面
【发布时间】:2013-03-09 15:04:44
【问题描述】:

我正在构建一个 Phonegap 应用程序。我有 7-8 页,我需要使用 Javascript 在它们之间导航。我尝试过使用window.openwindow.location,但它们不起作用。

如何使用 Javascript 更改页面?

【问题讨论】:

  • window.location.href 和 window.open() 应该都可以工作。可以发一些代码吗?
  • 是的,你是对的,window.open() 有效,但它打开弹出窗口...关于 window.location.href - 无效,这里代码:
  • 使用window.open("ltr.startPage.html?tagId=-1", "_self")在同一个窗口中打开一个页面
  • 谢谢,看来这个可行,但最好使用Phonegap浏览器,InAppBrowser:window.open('apache.org', '_blank', 'location=yes');

标签: javascript cordova navigation


【解决方案1】:

以下代码对我有用。

window.location="success.html";

登录成功后,我正在调用上面的代码。它正在重定向到android phonegap中的成功页面。

【讨论】:

  • 对我不起作用。它切换到显示Cannot GET /noConnection.html 的空白页面。我正在尝试显示页面是用户没有连接。
【解决方案2】:

试试这个。我想它会对你有所帮助。

HTML

<a href="#" onClick="goPage1();">Go to Page1</a>

JavaScript:

function goPage1()
{
   var dirPath = dirname(location.href);
   fullPath = dirPath + "/page1.html";
   window.location=fullPath;
}
function dirname(path)
{
   return path.replace(/\\/g,'/').replace(/\/[^\/]*$/, '');
}

【讨论】:

  • 对我不起作用。它切换到显示Cannot GET /noConnection.html 的空白页面。我试图显示页面是用户没有连接。就像上面的解决方案一样。
【解决方案3】:

如果它是相同的主机名,您可以简单地使用 pathname 更改页面:

例如,如果您有文件名:

index.html

登录.html

您可以使用 :

转到 login.html
window.location.pathname = "login.html";

【讨论】:

    猜你喜欢
    • 2023-03-24
    • 1970-01-01
    • 2020-12-30
    • 2014-03-09
    • 1970-01-01
    • 2013-03-27
    • 2017-11-10
    • 2023-04-02
    • 1970-01-01
    相关资源
    最近更新 更多