关闭选项卡之前确认框 [英] Confirm box before closing a tab
本文介绍了关闭选项卡之前确认框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当用户尝试关闭窗口时,我想要一个确认框.
I want to have a confirm box when user tries to close the window.
window.onbeforeunload = function (evt) {
var message = 'Are you sure you want to leave, cause there are some unsaved changes?';
if (typeof evt == 'undefined') {
evt = window.event;
}
if (evt) {
evt.returnValue = message;
}
return message;
}
我要检查变量值
var sncro = 1;
如果其值不等于1,则此确认框应存在,否则无需确认.我不知道这一点.它是如此愚蠢,但我要求任何人都可以看一下代码.
If its value is not equal to one then this confirmation box should be there, else no need to have a confirmation. I'm not able to figure this. Its so silly but I request anybody can have a look on the code.
推荐答案
我假设在页面加载时,您正在设置var sncro = 1;当某些数据更改时,您可以调整此值.这是快速检查:
I assume that on page load, you are setting up var sncro=1; and when some data changes, you adjust this value. Here is the quick check:
window.onbeforeunload = function (evt) {
if (sncro != 1) {
var message = 'Are you sure you want to leave, cause there are some unsaved changes?';
if (typeof evt == 'undefined') {
evt = window.event;
}
if (evt ) {
evt.returnValue = message;
}
return message;
}
}
这篇关于关闭选项卡之前确认框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文