onbeforeunload - Return confirm in JavaScript - Stack Overflow

I have problem with return confirm in Chrome. In Firefox it is ok.window.onbeforeunload = function() {v

I have problem with return confirm in Chrome. In Firefox it is ok.

window.onbeforeunload = function() {
    var result = confirm('Really?');

    if(result) {
        console.log('Do something');
    }
}

Any ideas? Thanks!

I have problem with return confirm in Chrome. In Firefox it is ok.

window.onbeforeunload = function() {
    var result = confirm('Really?');

    if(result) {
        console.log('Do something');
    }
}

Any ideas? Thanks!

Share Improve this question edited Jan 3, 2013 at 12:40 honzahommer asked Jan 3, 2013 at 12:32 honzahommerhonzahommer 8393 gold badges10 silver badges15 bronze badges 7
  • What problem do you have with it in Chrome? – Quentin Commented Jan 3, 2013 at 12:34
  • 1 8 question and 0% accept ratio.... u need to work on that first...:) – bipen Commented Jan 3, 2013 at 12:34
  • jQuery confirmation not working in Chrome – Felipe Fonseca Commented Jan 3, 2013 at 12:34
  • Wild speculation: Your problem is that you have the Chrome developer tools set to clear the console.log history when the page changes or is reloaded. – Quentin Commented Jan 3, 2013 at 12:35
  • 1 function { is a syntax error btw (type in the post I assume). – Felix Kling Commented Jan 3, 2013 at 12:35
 |  Show 2 more ments

2 Answers 2

Reset to default 5

You should return something from beforeunload.

The confirm will be ignored

Since 25 May 2011, the HTML5 specification states that calls to window.showModalDialog(), window.alert(), window.confirm() and window.prompt() methods may be ignored during this event.

see MDN

window.onbeforeunload = function() {
    return 'Date will be lost: are you sure?'; //<= here
}

If you don't return something, the actions within the handler function are executed before the page unloads.

You can't use dialogs (in some browsers) when a user is trying to leave the page. Otherwise you could just put a constant stream of alerts.

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

相关推荐

  • onbeforeunload - Return confirm in JavaScript - Stack Overflow

    I have problem with return confirm in Chrome. In Firefox it is ok.window.onbeforeunload = function() {v

    11小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信