+ 5

How to create an alert box that would visible at end for users

#endalert

7th Jan 2019, 2:41 PM
NARESH KUMAR
NARESH KUMAR - avatar
2 ответов
+ 3
window.onbeforeunload=function(){ return "foo?" // if you want a prompt, return something } ...works for me here. Probably best used to rescue users from accidentally losing unsaved work. Using it to trap users on your pages will just alienate your audience. I use this event to stop timers (clearInterval, clearTimeout, cancelAnimationFrame).
7th Jan 2019, 6:04 PM
Kirk Schafer
Kirk Schafer - avatar
+ 1
There is an event listener about leaving the current page. But such malicious act will be blocked by modern browsers, hence your attempt will not be effective even if the syntax is all correct.
7th Jan 2019, 3:13 PM
Gordon
Gordon - avatar