How to create an alert box that would visible at end for users | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 5

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

#endalert

7th Jan 2019, 2:41 PM
NARESH
NARESH - 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