如何在Mozilla firefox中关闭浏览器时提醒用户

本文关键字:浏览器 用户 Mozilla firefox | 更新日期: 2023-09-27 17:58:41

请建议在Mozilla firefox中关闭浏览器时提醒用户的方法。我已经尝试了IE和Chrome的onbeforenload,它在两者中都有效。但是我无法在Firefox中得到相同的响应。onbeforeunload和onunload似乎在Firefox中不起作用。此外,在一些博客中,我发现onbeforeunload只适用于Firefox 4.0或更低版本。我试过下面的javascript代码,它在IE和Chrome中对我有效,但在Firefox中无效。

<script language="JavaScript" type="text/javascript">
        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;
        });
</script>

如果有其他选择,不胜感激。

如何在Mozilla firefox中关闭浏览器时提醒用户

你试过这个吗?

window.onbeforeunload = function () {
    return "Do you want to close?";
};
相关文章: