hema
hema

Reputation: 1

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

Confirm dialog on leaving page

how to do that?

Upvotes: 0

Views: 286

Answers (2)

ChristopheCVB
ChristopheCVB

Reputation: 7315

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;

Upvotes: 0

sahid
sahid

Reputation: 2610

You need to use the event, "onbeforeunload" attached has the window:

https://developer.mozilla.org/en/DOM/window.onbeforeunload

Upvotes: 1

Related Questions