Force mouse click on popup window
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?
You need to use the event, "onbeforeunload" attached has the window:
https://developer.mozilla.org/en/DOM/window.onbeforeunload
Have a look on "unload" event ;)
http://jsfiddle.net/K5FzG/1/
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;
精彩评论