$(window).bind('beforeunload', function() {return 'Are you shure?';} );
开发者_JS百科
How I must do that if user click CANCEL button page will be redirect to http://mypage.com?
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.
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
精彩评论