使用“ beforeunload”后如何恢复默认操作(无需确认即可退出)

时间:2018-11-29 08:55:57

标签: javascript

使用“ beforeunload”后如何恢复默认操作(无需确认即可退出)。

我在全球范围内使用:

window.addEventListener("beforeunload", function( event ) {
    event.returnValue = "Some text";
});

但是我希望在按下一个特定按钮后,没有消息,并且页面正常加载。

        $("#button").on("click", function() {
            window.addEventListener("beforeunload", function( event ) {
                event.returnValue = false;
                event.preventDefault();
                console.log(event);
            });

            window.location.href = "https://google.com/";
        });

window.onbeforeunload = null;

我尝试过几种方法,但我做不到。

0 个答案:

没有答案