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() {