From 0f5b8a4f528e748a03eab413663c6b38fd5ac87f Mon Sep 17 00:00:00 2001 From: lkddi Date: Sun, 1 Mar 2026 00:16:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9AChrome=20=E7=82=B9?= =?UTF-8?q?=E5=87=BB=E7=A6=BB=E5=BC=80=E6=97=B6=E5=87=BA=E7=8E=B0=E5=8E=9F?= =?UTF-8?q?=E7=94=9F"=E7=A6=BB=E5=BC=80=E7=BD=91=E7=AB=99"=E5=BC=B9?= =?UTF-8?q?=E7=AA=97=E9=97=AA=E7=83=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 主动调用 remove 移除 beforeunload 监听后再导航, Chrome 不再触发原生确认框,Edge 行为不变 --- resources/views/chat/partials/scripts.blade.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/resources/views/chat/partials/scripts.blade.php b/resources/views/chat/partials/scripts.blade.php index 01b658c..7f1acdb 100644 --- a/resources/views/chat/partials/scripts.blade.php +++ b/resources/views/chat/partials/scripts.blade.php @@ -951,6 +951,10 @@ // ── 退出房间 ───────────────────────────────────── async function leaveRoom() { + // 主动移除 beforeunload 监听,防止 Chrome 触发"离开网站?"原生弹窗 + window.removeEventListener('beforeunload', sendLeaveBeacon); + clearTimeout(visibilityTimer); + try { await fetch(window.chatContext.leaveUrl, { method: 'POST', @@ -970,6 +974,7 @@ }, 500); } + // ── 关闭/离开页面时自动调用 leave,结算勤务时长 ────────────────────── // 使用 sendBeacon 确保浏览器关闭时请求也能发出(比 fetch 更可靠) function sendLeaveBeacon() {