From c0480f888db7e5418a2e05da0dbc90edbf1fe1c5 Mon Sep 17 00:00:00 2001 From: duanyu5871 <344094952@qq.com> Date: Thu, 16 Oct 2025 09:50:09 +0800 Subject: [PATCH] beforeunload event listener update (#1107) * beforeunload update * Rename to EJS_disableAutoUnload * Remove value from index.html since undefined is a falsy value --------- Co-authored-by: Ethan O'Brien Co-authored-by: Ethan O'Brien <77750390+ethanaobrien@users.noreply.github.com> --- data/loader.js | 1 + data/src/emulator.js | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/data/loader.js b/data/loader.js index 4c0ec1a..96796ab 100644 --- a/data/loader.js +++ b/data/loader.js @@ -127,6 +127,7 @@ config.browserMode = window.EJS_browserMode; config.shaders = Object.assign({}, window.EJS_SHADERS, window.EJS_shaders ? window.EJS_shaders : {}); config.fixedSaveInterval = window.EJS_fixedSaveInterval; + config.disableAutoUnload = window.EJS_disableAutoUnload; let systemLang; try { diff --git a/data/src/emulator.js b/data/src/emulator.js index ca74f56..7c16a70 100644 --- a/data/src/emulator.js +++ b/data/src/emulator.js @@ -1159,6 +1159,11 @@ class EmulatorJS { }, 0); }); this.addEventListener(window, "beforeunload", (e) => { + if (this.config.disableAutoUnload) { + e.preventDefault(); + e.returnValue = ""; + return + } if (!this.started) return; this.callEvent("exit"); });