I want to add a message for example: If the user leaves the browser tab, the message "Looks like you're gone ..." should appear. When the user returns to the page, change the message to "Good to be back".
Is it possible to do something like this?
I want to add a message for example: If the user leaves the browser tab, the message "Looks like you're gone ..." should appear. When the user returns to the page, change the message to "Good to be back".
Is it possible to do something like this?
Crate an eventListener
on your window, with the load
event, and simply show an alert.
And create an event on your window
called onbeforeunload
(more info about the event), where you show an alert while leaving the page.
Note: onbeforeunload
won't work in this snippet, but try putting inside your code.
window.addEventListener('load', (event) =>{
alert("Looks like you are back");
});
window.onbeforeunload = function() {
alert("Looks like you want to leave");
};