使用 Javascript 更改页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15312158/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Changing page using Javascript
提问by user1058043
I building a Phonegap application. I have 7-8 pages, and I need to navigate between them using Javascript. I have tried usingwindow.open
and window.location
but those don't work.
我构建了一个 Phonegap 应用程序。我有 7-8 页,我需要使用 Javascript 在它们之间导航。我试过使用window.open
,window.location
但那些不起作用。
How do I change the page using Javascript?
如何使用 Javascript 更改页面?
回答by Naresh
the following code working for me.
以下代码对我有用。
after login success I am calling above code. It is redirecting to success page in android phonegap.
登录成功后,我正在调用上面的代码。它正在重定向到 android phonegap 中的成功页面。
回答by Shashi
Try this. i think it will help you.
试试这个。我认为它会帮助你。
HTML
HTML
<a href="#" onClick="goPage1();">Go to Page1</a>
JavaScript:
JavaScript:
function goPage1()
{
var dirPath = dirname(location.href);
fullPath = dirPath + "/page1.html";
window.location=fullPath;
}
function dirname(path)
{
return path.replace(/\/g,'/').replace(/\/[^\/]*$/, '');
}