您的位置:首页 > Web前端 > JavaScript

js屏蔽backspace键/点击浏览器后退按钮提示

2016-01-28 09:12 525 查看
//屏蔽系统里的backspace键
$(document).on("keydown", function () {
if (event.keyCode == 8) {
if (document.activeElement.type == "text") {
if (document.activeElement.readOnly == false)
return true;
}
return false;
}
});

//离开当前页面(比如页面跳转)所触发的事件函数
window.onbeforeunload = function (e) {
if (GObj == null || GObj.length < 1 || $(parent.document).find('.ui-dialog').length < 1)
return;
return "";
};

//该事件函数紧跟在onbeforeunload后面执行(当然是要在onbeforeunload有返回值的情况下才执行,否则不执行)
$(window).unload(function () {
if (GObj !== null && GObj.length > 0)
GObj.dialog("close");
return;
});

//设置一个全局变量存储模态对话框,以便后续如果点击浏览器的后退键时获取对话框对象进行处理
var GObj = null;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: