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 <ethan.a.obrien@gmail.com>
Co-authored-by: Ethan O'Brien <77750390+ethanaobrien@users.noreply.github.com>
This commit is contained in:
duanyu5871 2025-10-16 09:50:09 +08:00 committed by GitHub
parent 54d7dfbc1f
commit c0480f888d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 0 deletions

View File

@ -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 {

View File

@ -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");
});