开发者

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

Force mouse click on popup window

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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜