Javascript onbeforeunload关闭浏览器窗口 [英] Javascript onbeforeunload close browser window
本文介绍了Javascript onbeforeunload关闭浏览器窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我现在有一个很小的脚本,用于检查表单上是否有任何更改.如果有变化
然后我将标志设置为"Y".我在body标签中的onBeforeunload ="changeConfirm()"位置上调用此函数.我知道
我无法阻止用户关闭窗口,但是在他进行了更改的情况下,如何使该方案起作用
->决定关闭窗口->脚本警告他->用户点击取消(现在我需要将他带回屏幕
而不是关闭浏览器.
I have this tiny script for now that checks if any change is made on the form. If there is a change
then I set a flag to 'Y'. I call this function on onBeforeunload="changeConfirm()" places in the body tag. I know
I can't stop the user from closing down the window, but how do I make this scenario work where he made a change
-> decide to close the window -> Script alerted him -> User clicks cancel (Now I need to bring him back to the screen
instead of closing browser.
<script type="text/javascript">
var Flag= "";
function changeConfirm(){
if(Flag == 'Y')
{
var confirmStatus = confirm('Changes made. Dont want to save?');
}
else {
alert("No changes were made " + Flag);
}
}
</script>
推荐答案
尝试一下:
function confirmChanges() {
if(Flag == 'Y')
{
if(confirm('Changes made. Dont want to save?')){
return false;
}else{
return true;
}
}
else {
alert("No changes were made " + Flag);
}
}
这篇关于Javascript onbeforeunload关闭浏览器窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文