+ 5

Closing web tab

I've seen this on a few websites, where when you close a tab and an important process is running it asks the client if they want really want to leave. I would like to know if it's the web browser itself, or specific Javascript code. If it is Javascript code, what code would it be? and where can I read more on it?

4th Sep 2017, 5:21 PM
Limitless
Limitless - avatar
4 ответов
+ 5
here's a snippet from Stackoverflow.com window.onbeforeunload = function() { return "Hey, you're leaving the site. Bye!"; };
4th Sep 2017, 5:36 PM
cHiRaG GhOsH
cHiRaG GhOsH - avatar
+ 4
@Limitless its a confirm box (javascript code) here is a snippet copied from the javascript course:- var result = confirm("Do you really want to leave this page?"); if (result == true) { alert("Thanks for visiting"); } else { alert("Thanks for staying with us"); }
4th Sep 2017, 5:25 PM
cHiRaG GhOsH
cHiRaG GhOsH - avatar
+ 4
So how do we determine if the user is trying to close the tab?
4th Sep 2017, 5:27 PM
Limitless
Limitless - avatar
+ 3
@empty check the course !!!
4th Sep 2017, 5:26 PM
cHiRaG GhOsH
cHiRaG GhOsH - avatar