Javascript 窗口位置无法正常工作
大家好,我正在从一个html页面导航到另一个html页面,如下所示:Javascript 窗口位置无法正常工作,javascript,jquery,blackberry,jquery-mobile,cordova,Javascript,Jquery,Blackberry,Jquery Mobile,Cordova,大家好,我正在从一个html页面导航到另一个html页面,如下所示: window.location = "test.html"; 在test.html中,我的标题为: <script type="application/javascript"> function redirect() { alert("inside redirect:"); //window.lo
window.location = "test.html";
在test.html中,我的标题为:
<script type="application/javascript">
function redirect()
{
alert("inside redirect:");
//window.location = url;
//history.back();
history.go(-1);
return false;
}
</script>
<div data-role="navbar">
<ul>
<li> <a href="#" data-theme="b" onclick="history.back(); return false;">Go Back</a></li>
<li> <a onclick="redirect()" data-icon="back" data-iconpos="notext" data-direction="reverse" class="ui-btn-left jqm-home">Back1</a></li>
</ul>
</div>
函数重定向()
{
警报(“内部重定向:”);
//window.location=url;
//历史。返回();
历史。go(-1);
返回false;
}
- 背景1
但是这里的两个后退按钮(返回和后退1)都不起作用。如果我使用$.mobile.changePage('test.html')
在页面之间导航,那么两个后退按钮都可以工作。为什么不使用windows.location
我想为不支持ajax的B级浏览器开发这个应用程序。因此,我不能使用$.mobile.changePage('test.html')
任何帮助都将不胜感激。谢谢。试试看:
window.location.href = "test.html";
或:
window.location.assign("test.html");
试试看:
window.location.href = "test.html";
或:
window.location.assign("test.html");
为什么不使用
window.location.replace(“test.html”)
为什么不使用window.location.replace(“test.html”)
在jQuery mobile中,您可以通过设置一些变量来使用ajax。在加载jQuery mobile之前,需要加载此脚本
$(document).bind("mobileinit", function(){
//apply overrides here
$.mobile.ajaxEnabled = false;
});
关闭ajax后,您现在仍然可以使用$.mobile.changePage()
现在要创建一个后退按钮,您所要做的就是给链接一个
在jQuery mobile中,您可以通过设置一些变量来启用ajax。在加载jQuery mobile之前,需要加载此脚本
$(document).bind("mobileinit", function(){
//apply overrides here
$.mobile.ajaxEnabled = false;
});
关闭ajax后,您现在仍然可以使用$.mobile.changePage()
现在要创建一个后退按钮,您所要做的就是给链接一个
这款黑莓操作系统5浏览器存在很多问题。起初我也试着做你现在正在做的事情。但后来我想你会想到其他更好的方法。我是这样解决的
首先,在像这样加载jquery移动脚本之前添加这些行
<script type="text/javascript">
$(document).bind("mobileinit", function() {
$.support.cors = true;
$.mobile.allowCrossDomainPages = true;
});
</script>
<div data-role="page" id="page1">
<div data-role="page" id="page2">
.
.
.
$.mobile.changePage("#page1", {
transition : "slide"
});
然后,您可以像这样轻松地执行changePage
<script type="text/javascript">
$(document).bind("mobileinit", function() {
$.support.cors = true;
$.mobile.allowCrossDomainPages = true;
});
</script>
<div data-role="page" id="page1">
<div data-role="page" id="page2">
.
.
.
$.mobile.changePage("#page1", {
transition : "slide"
});
我希望您采取正确的方法。这款黑莓OS 5浏览器存在很多问题。起初我也试着做你现在正在做的事情。但后来我想你会想到其他更好的方法。我是这样解决的 首先,在像这样加载jquery移动脚本之前添加这些行
<script type="text/javascript">
$(document).bind("mobileinit", function() {
$.support.cors = true;
$.mobile.allowCrossDomainPages = true;
});
</script>
<div data-role="page" id="page1">
<div data-role="page" id="page2">
.
.
.
$.mobile.changePage("#page1", {
transition : "slide"
});
然后,您可以像这样轻松地执行changePage
<script type="text/javascript">
$(document).bind("mobileinit", function() {
$.support.cors = true;
$.mobile.allowCrossDomainPages = true;
});
</script>
<div data-role="page" id="page1">
<div data-role="page" id="page2">
.
.
.
$.mobile.changePage("#page1", {
transition : "slide"
});
我希望您采取正确的方法。然后尝试
window.location.assign(“test.html”)代码>感谢您的回复。但是window.location.assign(“test.html”);也不起作用看这把小提琴:你能根据你的要求创建一把小提琴吗。如何在小提琴中添加两个独立的html文件。因为在我的应用程序中,我有两个独立的html文件。我从一个html文件调用另一个。然后尝试window.location.assign(“test.html”)代码>感谢您的回复。但是window.location.assign(“test.html”);也不起作用看这把小提琴:你能根据你的要求创建一把小提琴吗。如何在小提琴中添加两个独立的html文件。因为在我的应用程序中,我有两个独立的html文件。我从一个html文件调用另一个。你特别针对哪个手机和操作系统?黑莓操作系统5?是的。如果我使用window.location.assign(“first.html”);然后它从test.html导航到first.html,但当我按下mobile的back按钮(硬件按钮)时,它再次导航到test.htmlwhat$.mobile.changePage('test.html')
中的问题,它的工作非常好,没有$.mobile.changePage('test.html'))不在blackberry5中运行。我已经使用changePage
1000次为BB OS 5编写了整个应用程序。。。你只需要禁用ajax就可以了……你特别针对哪个手机和操作系统?黑莓操作系统5?是的。如果我使用window.location.assign(“first.html”);然后它从test.html导航到first.html,但当我按下mobile的back按钮(硬件按钮)时,它再次导航到test.htmlwhat$.mobile.changePage('test.html')
中的问题,它的工作非常好,没有$.mobile.changePage('test.html'))不在blackberry5中运行。我已经使用changePage
1000次为BB OS 5编写了整个应用程序。。。你只需要禁用ajax就行了……我用BB5试过了。我有三个html文件1,2,3.html。在每个文件中都有一个按钮和一次单击按钮,我称之为$.mobile.changePage('2.html')。但当我从1转到2.html时,它会显示一个进度条(我没有添加ehich),2.html不会显示,这里它仍然显示一个带有进度条的.html。在第二个场景中,我只有1.html和2.html在这里单击one.html的按钮,它显示2.html,但这里也显示进度条。在BB6上,同样的代码在这两种情况下都能完美运行。请参阅,无论何时调用新的html页面,都会卸载加载的旧脚本,然后再次加载第二个html中的新脚本。这会占用内存和时间。这对于移动设备来说是低效的。这就是为什么我希望你有一个单一的HTML文件,这样你只需加载脚本一次…你的Index.HTML将是巨大的,但它将是高效和快速的。。。尝试通过添加注释使代码可读。。。其他一切都会好的:)祝你好运。。。你知道使用这种方法会在很多方面帮助你。。例如,localStorage在BBOS5上不起作用,但是如果您只有一个文件,那么您可以使用全局变量来代替。。。您将慢慢了解所有优点:)您需要注册backbutton侦听器,并捕获当前显示的页面的id,然后相应地移动页面。。使用$.mobile.activePage.attr('id')
我用BB5试过。我