我已经实施了
的建议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中缺少用户交互。如果用户在显示用户确认消息后与页面进行交互。