suppress confirmation dialog while using onbeforeunload

南笙酒味 提交于 2019-12-01 05:48:39

As per my comments on the original post, the answer is to make the call synchronous by adding async: false in the Ajax call settings, change the last return false to return null;, and remove the done function:

window.onbeforeunload = unloadFunction;
function unloadFunction() {
    var test_id = $('#test_id').val();

    jQuery.ajax({
        url: "/test/cleanup/" + test_id,
        cache: false,
        async: false
    });

    return null;
}

When the user closes the page the document is dead, the scripts are dead. You're expecting the script to run after they close. Now if the tab doesn't close it feels like it's frozen waiting for your function to finish. Meaning it's not possible. I believe that's what you want? The clean up request won't send because the document is closed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!