Skip to content

Commit 57c6c37

Browse files
add event beforeunload and visibility change
1 parent b8f488d commit 57c6c37

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

Clock Time.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,4 +308,21 @@ function addIframe() {
308308

309309
iframe.parent(container);
310310
iframe.position(posXIframe* factorScale,posYIframe* factorScale);
311-
}
311+
}
312+
313+
window.addEventListener('beforeunload', (event) => {
314+
// Cancel the event as stated by the standard.
315+
event.preventDefault();
316+
// Chrome requires returnValue to be set.
317+
event.returnValue = '';
318+
});
319+
320+
document.addEventListener('visibilitychange', function() {
321+
if (document.hidden) {
322+
console.log('User switched to another tab');
323+
alert('You have switched to another tab!');
324+
} else {
325+
console.log('User switched back to the tab');
326+
alert('Welcome back to the tab!');
327+
}
328+
});

0 commit comments

Comments
 (0)