javascript - Confirm message on browser page close - Stack Overflow

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

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

How I must do that if user click CANCEL button page will be redirect to ?

$(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.?

Share Improve this question edited Dec 2, 2010 at 19:49 user515503 asked Dec 2, 2010 at 19:35 user515503user515503 2051 gold badge5 silver badges14 bronze badges 2
  • 1 Were they already going there? or you want to redirect them to somewhere unexpected? – Nick Craver Commented Dec 2, 2010 at 19:39
  • If user want close page in brawser, that brawser send confirm message and if they click CANCEL button that page is redirect! No OK button! Sorry – user515503 Commented Dec 2, 2010 at 19:49
Add a ment  | 

2 Answers 2

Reset to default 5

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745484164a4629691.html

相关推荐

  • javascript - Confirm message on browser page close - Stack Overflow

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

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信