window.onbeforeunload没有在chrome中显示消息

时间:2016-06-24 04:16:31

标签: javascript google-chrome

当用户试图离开时,我会在某些条件下显示提醒消息。该消息显示在Safari中,但它在Chrome中不起作用 我尝试过以下两件事:

window.onbeforeunload = function(event) {
    if ($scope.isFormChanged == true) {
        event.returnValue = 'Don\'t go yet! Save your changed data before you leave!';
    }
}

    window.onbeforeunload = function() {
        if ($scope.isFormChanged == true) {
            return 'Don\'t go yet! Save your changed data before you leave!'
        }
    }

1 个答案:

答案 0 :(得分:0)

我认为这适用于chrome。我也怀疑isFormChanged。

<script type="text/javascript"> window.onbeforeunload = function() { return "Are you sure you want to close window?" } </script>