+ 1

How do I alert the user in javascript when exiting site?

Javascript code to create an alert when user tries to exit website.

27th Sep 2019, 8:51 PM
Anthony Kwesi Saah
Anthony Kwesi Saah - avatar
6 Answers
+ 2
See this function: window.onbeforeunload = function () {}
27th Sep 2019, 9:18 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 2
Kk.
28th Sep 2019, 9:25 AM
Anthony Kwesi Saah
Anthony Kwesi Saah - avatar
+ 1
Thanks..It worked
28th Sep 2019, 9:11 AM
Anthony Kwesi Saah
Anthony Kwesi Saah - avatar
+ 1
<script type="text/javascript"> window.onbeforeunload = confirmExit; function confirmExit() { return "Do you want to leave this page without saving?"; } </script>
28th Sep 2019, 9:51 AM
Anthony Kwesi Saah
Anthony Kwesi Saah - avatar
0
Please, show me how it worked... 😉
28th Sep 2019, 9:21 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
Thx! maybe return will be in ()?
28th Sep 2019, 9:52 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar