There is a lot of questions on stackoverflow.com about this issue. But there is really no answer, or I couldn't find it (in that case, I am sorry for this duplicate).
So I have an Ajax based web application, and I want to know if user want's to leave the page. Here's a snippet what I have:
function goodbye(e) {
if(!stopGoodbye) {
if(!e) e = window.event;
e.cancelBubble = true;
e.returnValue = 'You are leaving the system!';
if (e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
}
}
}
window.onbeforeunload=goodbye
stopgoodbye
is for turning off when clicking logout.
This works in Firefox, but in IE9 it is showing the dialog everytime user clicks a link which just changes some DIV content (an Ajax link)... If it helps, I am using Struts2 framework with jQuery.
you can actually turn the onbeforeupload warning off for the user(when they clicked on a link) by adding an onclick event to the anchor.
you can read more about here , the solution are in the comments
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.