Hello.
When I move the screen, refresh the page, or close the browser, I want to pop up an alert window and when I click cancel, I want to stay on the original screen.
I've seen several posts on the forum with the same problem as mine.
I was able to find a solution like the following image.
However, it doesn't work perfectly.
It pops up an alert window when I try to refresh or close the page,
but when I try to move the screen using the menu button, the event doesn't work.
Can someone help me?
@GeonOh Hwang ,
i try next code and work with me on refresh and move
window.addEventListener('beforeunload', function(event) {
event.preventDefault(); // Prevent the default action of closing the window or tab
return 'Are you sure you want to leave?'; // Display a confirmation message
});
window.addEventListener('blur', function() {
alert('You are about to leave the page. Are you sure?'); // Display an alert when the window loses focus