gpt4 book ai didi

javascript-events - window.onbeforeunload 检测 POST 或 GET

转载 作者:行者123 更新时间:2023-12-01 23:01:35 24 4
gpt4 key购买 nike

在 window.onbeforeunload 事件中有没有办法检测新请求是 POST(在同一页面上)还是 GET(转到页面)?看到新的 document.location 也会很棒。

window.onbeforeunload = winClose;
function winClose() {
//Need a way to detect if it is a POST or GET
if (needToConfirm) {
return "You have made changes. Are you sure you want?";
}
}

最佳答案

我就是这样做的:

$(document).ready(function(){
var action_is_post = false;
$("form").submit(function () {
action_is_post = true;
});

window.onbeforeunload = confirmExit;
function confirmExit()
{
if (!action_is_post)
return 'You are trying to leave this page without saving the data back to the server.';
}
});

关于javascript-events - window.onbeforeunload 检测 POST 或 GET,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/552415/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com