[英]jquery mobile history.back() only work for first time
currently I have encountered a problem with history. 目前,我遇到了历史记录问题。 back (). 背部 ()。
I have 2 pages, which is pageA.html, pageB.html. 我有2页,分别是pageA.html,pageB.html。
I'm using the following code for go to next page and back to previous page 我正在使用以下代码转到下一页并返回上一页
// go to next page
function changePage(url) {
$.mobile.pageContainer.pagecontainer("change", url, {
allowSamePageTransition: true,
transition: 'none',
showLoadMsg: false,
reloadPage: false,
changeHash: true
})
}
//back to previous page
function backToPreviousPage(){
alert("back");
history.back();
}
The codes work fine for the first time, as the flow below 代码首次正常运行,如下所示
First time : pageA > pageB (click on back button once) > pageA 第一次:pageA> pageB(单击返回按钮一次)> pageA
So I have successfully back to pageA again. 所以我已经成功地回到了pageA。 And here's the problem comes. 问题来了。
Second time : pageA > pageB (first click back button no respond, then click for second time) > pageA 第二次:pageA> pageB(先单击后退按钮无响应,然后第二次单击)> pageA
When it comes to third time, I need to click on the back button 3 times then only can make the history.back() work, I can get the alert message, so the backToPrevious function is called. 到第三次时,我需要单击后退按钮3次,然后才能使history.back()工作,我可以获得警报消息,因此调用了backToPrevious函数。
so the problem is like below: 所以问题如下:
and so on.... 等等....
Ii can't just hardcode navigate back to pageA in the backToPrevious function, because I not only can navigate to pageB from pageA, but also can navigate pageB from other page. 我不仅可以在backToPrevious函数中硬编码导航回pageA,因为我不仅可以从pageA导航到pageB,而且可以从其他页面导航到pageB。
So far I have tried with this 到目前为止,我已经尝试过
history.back(-1);
and this 和这个
<a data-rel="back" href="javascript:history.back(1)" data-theme="a">Back</a>
but still can't fix the problem. 但仍然无法解决问题。
Appreciate if anyone can tell me what am i doing wrong. 欣赏是否有人可以告诉我我在做什么错。 Thank you. 谢谢。
Just use this code. 只需使用此代码。
function changePage() {
$.mobile.changePage("pageA.html");
return false;
}
function backToPreviousPage(){
navigator.app.backHistory();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.