Javascript Firefox没有';除非单击页面,否则不要调用'beforeunload'事件
我想在Firefox中处理Javascript Firefox没有';除非单击页面,否则不要调用'beforeunload'事件,javascript,jquery,html,css,firefox,Javascript,Jquery,Html,Css,Firefox,我想在Firefox中处理beforeunload事件。它工作正常,只是用户需要手动单击页面或在输入中写入内容 我有下面的一段代码可以在Firefox上运行,但同样,只有手动点击页面 <script> popMessage = "Foo"; window.addEventListener("beforeunload", function (e) { (e || window.event).returnValue = popMessage; //
beforeunload
事件。它工作正常,只是用户需要手动单击页面或在输入中写入内容
我有下面的一段代码可以在Firefox上运行,但同样,只有手动点击页面
<script>
popMessage = "Foo";
window.addEventListener("beforeunload", function (e) {
(e || window.event).returnValue = popMessage; //Gecko + IE
alert(popMessage);
return popMessage;
});
</script>
这些功能在Chrome上运行良好,但在Firefox上不起作用。如果没有用户在页面上的交互,是否有希望实现此功能?指出,“为了防止不必要的弹出窗口,浏览器可能不会显示在beforeunload事件处理程序中创建的提示,除非页面已与之交互。”因此没有希望
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script>
$(window).on('beforeunload', function(){
return 'Are you sure you want to leave?';
});
</script>