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.
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.
Also tried the solution mentioned in this question.But same result.