简体   繁体   English

浏览器关闭事件提示用户在IE和Firefox中无法使用

[英]Browser close event notiying user not working in IE and Firefox

I am using the following code to warn the user when he closes the browser.The code is working fine in Chrome.But its not working properly in IE(version 9) and in firefox(version 17).I mean some of the button clicks and hyperlink clicks shows the alert in firefox as well as in ie.Also some clicks in the kendo grid too.And this problem is not occuring in chrome.Its working fine every where in the application. 我正在使用以下代码在关闭浏览器时警告用户。该代码在Chrome中运行正常,但在IE(版本9)和firefox(版本17)中无法正常工作。我的意思是单击某些按钮超级链接点击会在Firefox和ie中显示警报。此外,在kendo网格中也会有一些点击。而且在chrome中不会出现此问题。它在应用程序中的每个位置都能正常工作。

var warningSuppressionTime = 0;
$(document).ready(function() {
   window.onbeforeunload = unloadPage;
   $("form").submit(dontWarn);
   $("button").on('click',dontWarn);
   $("a").on('click',dontWarn);
   $(".conten_wrp").on('click',dontWarn);//A common class in all pages where all the html is placed.
});

function unloadPage(){
    if (+new Date() - warningSuppressionTime > 1000) {
        return "Your changes will not be saved.";
    }
}
function dontWarn() {
    warningSuppressionTime = +new Date();
}

I am using kendo grid in my application.The click on buttons and <a> are also not working i the grid also.Can somebody suggest a solution. 我在应用程序中使用kendo网格。单击buttons<a>在网格中也无法正常工作。有人可以提出解决方案。 Also tried the solution mentioned in this question .But same result. 也尝试了这个问题中提到的解决方案。但是结果相同。

Make sure your code is wrapped in 确保您的代码包装在其中

$(document).ready(function()
{

});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM