Mozilla firefox无法使用window.onbeforeunload或window.beforeunload

时间:2016-11-07 06:48:53

标签: javascript jquery firefox

我已经实施了

的建议

window.onbeforeunload and window.onunload is not working in Firefox , Safari , Opera?

但它仍无效



 var myEvent = window.attachEvent || window.addEventListener;
        var chkevent = window.attachEvent ? 'onbeforeunload' : 'beforeunload'; 

        myEvent(chkevent, function (e) { 
           
            var confirmationMessage = 'Are you sure to leave the page?';
            (e || window.event).returnValue = confirmationMessage;
            return confirmationMessage;
        });




我试过这个但是它在mozilla中没有用。它只适用一次。请帮我解决这个问题。

我已经从测试过程中解决了这个问题。在Firefox中缺少用户交互。如果用户在显示用户确认消息后与页面进行交互。

1 个答案:

答案 0 :(得分:0)

为了用户的安全,Firefox不会显示beforeunloadunload 自定义消息。

Prior example of this question

相关问题