【问题标题】:How to block the popups alert on beforeUnload while using custom alert popup?如何在使用自定义警报弹出窗口时阻止 beforeUnload 上的弹出窗口警报?
【发布时间】:2018-11-30 11:53:40
【问题描述】:

当用户点击按钮时,我使用JqueryUI 自定义Confirm box

这是脚本,

    function exit() {
            $("#dialog-confirm").dialog({
                resizable: false,
                height: "auto",
                width: 400,
                modal: true,
                buttons: {
                    "Restore": function () {
                        callClick();
                    },
                    Cancel: function () {
                        $(this).dialog("close");
                    }
                }
            });
    }

这是 HTML 代码

    <asp:Button ID="btnExit" runat="server" Text="Exit" OnClientClick="exit()" />
    <div id="dialog-confirm" title="Proceed Confirmation?">
        <p>Are you sure you want to exit?</p>
    </div

当用户点击继续按钮时,我想调用另一个函数。

window.onbeforeunload = null;
        function callClick() {
            $('#test').click()
        }

但只要单击按钮,就会出现警报弹出窗口以及我自定义的警报弹出窗口。

我希望禁用默认弹出窗口。

请参阅下图以供参考。

【问题讨论】:

  • 您正在使用一个设置了runat="server" 的 ASP.Net 按钮,因此它将在任何 JS 运行之前卸载页面。
  • 什么是替代选项?

标签: javascript jquery jquery-ui alert confirm


【解决方案1】:

尝试使用window.onbeforeunload = function(event){}这个方法来捕捉这个事件。

【讨论】:

  • 我试过了,但没用。请检查我更新的问题
  • @Shahid,试着把它放在 window.onbeforeunload = null;上面的 callClick 函数
猜你喜欢
  • 1970-01-01
  • 2012-01-29
  • 1970-01-01
  • 1970-01-01
  • 2020-09-06
  • 2017-11-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多