1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-11 01:58:05 -05:00
denoland-deno/cli/tests/testdata/before_unload.js
Colin Ihrig 0f6a5c5fc2
feat(web): add beforeunload event (#14830)
This commit adds the 'beforeunload' event.

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2022-06-28 10:49:30 -04:00

21 lines
324 B
JavaScript

let count = 0;
console.log("0");
globalThis.addEventListener("beforeunload", (e) => {
console.log("GOT EVENT");
if (count === 0 || count === 1) {
e.preventDefault();
setTimeout(() => {
console.log("3");
}, 100);
}
count++;
});
console.log("1");
setTimeout(() => {
console.log("2");
}, 100);