user515503
user515503

Reputation: 205

Confirm message on browser page close

$(window).bind('beforeunload', function() {return 'Are you shure?';} );

How I must do that if user click CANCEL button page will be redirect to http://mypage.com?

Upvotes: 0

Views: 3942

Answers (2)

Jacob
Jacob

Reputation: 78850

You cannot change what happens when the user clicks one of the buttons in the dialog. This is intentional. Nobody wants to have web sites that mess with your navigation to that level.

Upvotes: 5

Breezer
Breezer

Reputation: 10490

yes you can u do

$(window).unload(function() {
    var answer = confirm("Are you sure?")
if (answer){
    alert("Bye bye!")
}else{
    alert("Thanks for sticking around!")
}

});

i just noticed that it wont prevent them from closing the window but it will show a confirmation when you close it >.<

it must be possible though since stackoverflow is doing it... try writing an answer and then close the windows you'll get a confirm box

Upvotes: 1

Related Questions