[英]JqueryMobile (SPA) Disable Browser backbutton and Refresh?
hi i am using jqueryMobile SPA template for my phone-gap app. 嗨,我正在为我的手机缺口应用程序使用jqueryMobile SPA模板。
For web version my requirement is to disable or show warning message to user on click of browser back button. 对于Web版本,我的要求是在单击浏览器后退按钮时禁用或向用户显示警告消息。 I googled my requirement but didn't find any desired solution.Please guide me .
我用Google搜索了我的要求,但没有找到所需的解决方案。请指导我。 Thanks.
谢谢。
To disable Backbutton of browser i used 要禁用我使用的浏览器的后退按钮
$(window).on("navigate", function (event) {
event.preventDefault();
window.history.forward(1);
});
But on pressing f5 it was creating error and redirecting me to login page.Thus i disable f5 ,ctrl+R button. 但是在按f5时,它正在创建错误并将我重定向到登录页面。因此我禁用了f5,ctrl + R按钮。
var ctrlKeyDown = false;
$(document).on("pagecreate", function (){
$(document).on("keydown", keydown);
$(document).on("keyup", keyup);
});
function keydown(e) {
if ((e.which || e.keyCode) == 116 || ((e.which || e.keyCode) == 82 && ctrlKeyDown))
{
// Pressing F5 or Ctrl+R
e.preventDefault();
} else if ((e.which || e.keyCode) == 17) {
// Pressing only Ctrl
ctrlKeyDown = true;
}
}
function keyup(e){
// Key up Ctrl
if ((e.which || e.keyCode) == 17)
ctrlKeyDown = false;
}
It completely fulfilled my requirement.Thanks to Suhas :) . 它完全满足了我的要求。感谢Suhas :)。
$(window).on("navigate", function (event, data) {
var direction = data.state.direction;
if ( !! direction) {
alert(direction);
}
});
Please refer following link. 请参考以下链接。
Or you can use 或者你可以使用
window.history.forward(1);
when back button get pressed. 当按下后退按钮时。 But it loads and then redirected not proper way.
但是它加载,然后重定向不正确的方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.