javascript - Firefox 网络浏览器中不显示确认消息

标签 javascript google-chrome firefox mozilla

每当用户尝试离开页面而不提交更改后的表单时,我正在使用在互联网上找到的脚本来生成确认消息。

这是我的脚本:

<script type="text/javascript">
  var formSubmitting = false;
  var setFormSubmitting = function() { formSubmitting = true; };

    var _isDirty = false;
    var setDirtyField = function() { _isDirty = true; }
    window.onload = function() {
    window.addEventListener("beforeunload", function (e) {
        var confirmationMessage = 'Nepamirškite užpildyti užduoties žurnalo! ';
        //confirmationMessage += 'If you leave before saving, your changes will be lost.';

        if (formSubmitting || !_isDirty) {
            return undefined;
        }
        else{
            (e || window.event).returnValue = confirmationMessage; //Gecko + IE
            return confirmationMessage; //Gecko + Webkit, Safari, Chrome etc.  
        }

    });
};
</script>

这就是我在 google chrome 中看到的脚本:

这就是我在 Firefox Web 浏览器中使用相同代码看到的结果: enter image description here

知道如何将我的文本添加到 Firefox 确认消息中吗?用我的替换现有文本将是完美的。

最佳答案

这是documented behaviour :

In Firefox 4 and later the returned string is not displayed to the user. Instead, Firefox displays the string "This page is asking you to confirm that you want to leave - data you have entered may not be saved." See bug 588292.

您无法覆盖默认文本。

关于javascript - Firefox 网络浏览器中不显示确认消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31717041/

相关文章:

Javascript Onfocus 在 Firefox 中的页面加载时触发

javascript - 为什么 page-mod 模块中的 onAttach 没有在 Firefox add-on sdk 中执行?

javascript - 重新加载页面而不向上滚动

css - Chrome 媒体查询行为

javascript - setState : function(){ mean 是什么意思

google-chrome - 在 chrome 扩展中,twitter bootstrap css 发生冲突

html - 在 Chrome 中禁用滚动

Firefox 动画硬件加速像素化边缘

javascript - 为什么这是一个永无休止的循环?

javascript - 与 ID 项建立链接