jquery - JQueryMobile - pagecontainerbeforeshow:从历史记录中删除上一页
问题描述
使用 jquery 和回调pagecontainerbeforeshow我想从导航历史记录中删除上一页 - 也就是说,如果用户从 page1 导航到 page2,并且用户单击后退按钮我想退出“应用程序”。
我在这里发现了同样的问题,但我不知道如何在 pagecontainerbeforeshow 中实现答案?
bindEvents: function() {
$(document).on("pagecontainerbeforeshow", function(event,ui){
var destinationPage = ui.toPage.prop("id");
var sourcePage = ui.prevPage.prop("id");
d.lg("destionationPage: " + destinationPage);
d.lg("sourcePage: " + sourcePage);
console.log("page to be shown =" + destinationPage);
switch(destinationPage) {
case 'restaurants':
d.lg('redirected to list');
break;
case 'offers':
d.lg('redirected to offers');
break;
}
});
}
解决方案
Bohr最终使用了另一种方法来改变后退按钮的行为。
如果存在div
withid=the_id_id_of_the_page
- 在
pagecontainerbeforeshow
事件中,backbutton
将与backButtonExit()
函数相关联 该
backButtonExit()
函数将触发应用程序的退出navigator.app.exitApp()
上
pagehide
的backButtonExit
功能将从中删除button
并且行为将停止$("#the_div_id_of_the_page").on('pagecontainerbeforeshow',function(){ document.addEventListener("backbutton", backButtonExit,false); }) $("#the_id_id_of_the_page").on('pagecontainerhide',function(){ document.removeEventListener("backbutton", backButtonExit,false); }) function backButtonExit(){ // Phonegap navigator.app.exitApp(); // Normal Browser window.close() }
这是一个比您的解决方案更简单的解决方案,但如果您需要,它也可以集成到您的switch
语句中。另外,如果您不使用phonegap,请考虑阅读这篇文章
推荐阅读
- python - 在for循环内删除np数组中的行
- android - 相对链接上的 Android WebView 新窗口空 URL
- express - 检查 express.js 中回调的返回
- r - 在 R tmap 中,如何在交互模式下向图例添加图层?
- email - hibernate-validator @email 长度大于 64 个字符
- mysql - MySQL 查询:ID 不相等且多个 LIKE 运算符不起作用
- jenkins - 在 jenkins ssh-agent 插件中找不到指定为参数的凭据
- java - 如果我在 application.properties 中使用 json 到 gson 映射器属性,为什么 swagger 不起作用
- c# - 向 GET API 调用添加参数
- swift - 我怎样才能分解一个大的初始化(由于大量的计算),以获得更好的可读性?