IE10上显示“离开此页面”消息两次 [英] 'Leave this page' message display twice on IE10

查看:222
本文介绍了IE10上显示“离开此页面”消息两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这些使用onbeforeunload的代码行要求用户在关闭页面之前保存他们的数据。该代码在Firefox和Firefox中运行良好。铬。

  window.onbeforeunload = function(){
if(isUpdated)return您有未保存的数据;
else返回undefined;
};



任何人都有解决这个问题的方法吗?

解决方案

添加 onbeforeunload 事件处理程序到 window.href 而不是窗口

  window.href.onbeforeunload = function(){
if(isUpdated){
return您有未保存的数据;
} else {
return undefined;
}
};


I have these line of code using onbeforeunload to ask user to save their data before closing the page. The code works well in Firefox & Chrome.

window.onbeforeunload = function () {
    if (isUpdated) return "You have unsaved data";
    else return undefined;
};

In IE (10), when I chose "Leave this page", everything's fine. But when I chose "Stay on this page", the popup closed and then display again, right after that, I have to click one more time on "Stay on this page", which I find annoying.

Anyone have a solution for this?

解决方案

Add the onbeforeunload event handler to window.href instead of window:

window.href.onbeforeunload = function () {
    if (isUpdated) {
        return "You have unsaved data";
    } else {
        return undefined;
    }
};

这篇关于IE10上显示“离开此页面”消息两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆