Reputation: 1
I have a simple project but i'm newbie in javascript, what I need is to force mouse to click on a dialog when the user leaves the page
how to do that?
Upvotes: 0
Views: 286
Reputation: 7315
Have a look on "unload" event ;)
On the unload call, you just need to call
confirm('Are you sure ?');
or like said in comment "onbeforeunload" if you want to use objects in page
function goodbye(e) {
if(!e) e = window.event;
//e.cancelBubble is supported by IE - this will kill the bubbling process.
e.cancelBubble = true;
e.returnValue = 'You sure you want to leave?'; //This is displayed on the dialog
//e.stopPropagation works in Firefox.
if (e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
}
}
window.onbeforeunload=goodbye;
Upvotes: 0
Reputation: 2610
You need to use the event, "onbeforeunload" attached has the window:
https://developer.mozilla.org/en/DOM/window.onbeforeunload
Upvotes: 1