onBeforeUnload自定义按钮消息 [英] onBeforeUnload custom button messages

查看:117
本文介绍了onBeforeUnload自定义按钮消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下我从其他地方偷来的beforeunload函数...。

I have the following beforeunload function which I have stolen from sonewhere else....

$().ready(function() {
    $("#posManagerLoginForm").trigger("submit");

    $(window).bind("beforeunload", function(){      
        window.setTimeout(function () {
            window.location = "home.htm";
        }, 0);
        window.onbeforeunload = null; // necessary to prevent infinite loop that kills your browser
        return "Press 'Stay On Page' to go to Reporting Manager home";
    });
});

不管我选择什么选项,我都会导航到home.htm。有没有一种方法可以使对话框成为确定按钮,而不是默认的离开页面或停留在页面上选项?

Regardless of what option I select I get navigated to home.htm. Is there a way that I can make the dialog box an ok button instead of the default "Leave Page" or "Stay on page" options?

或者也许其他人可以对热点提出更好的建议?

Or perhaps someone else could make a suggestion on hot to better handle?

谢谢

推荐答案

您不能覆盖 onbeforeunload 对话框的样式。相信我,我之前在较早的项目中就曾尝试过。

You cannot override the styling of the onbeforeunload dialog. Believe me, I tried this before in my earlier projects.

参考: http://msdn.microsoft.com/zh-cn/library/ms536907%28VS.85%29.aspx

它内置于浏览器对象中,您无法控制它。

您可以不过,请设置您自己的对话框以显示 onbeforeunload 事件何时触发,但不会禁止常规对话框显示。相当烦人,是的。

You can however set your own dialog to show when the onbeforeunload event triggers, but it will not disable that the regular one will show. Quite annoying, yes.

这篇关于onBeforeUnload自定义按钮消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆