Reputation: 1
I need a code that warns/alerts the user if they want to stay on or leave the Website when they click on a link that goes to another Website. I tried this and nothing happens.
Upvotes: 0
Views: 59
Reputation: 2583
Use the 'on before unload' event:
<script type="text/javascript">
window.onbeforeunload = onbeforeunload_handler;
window.onunload = onunload_handler;
function onbeforeunload_handler() {
// Do something here
}
function onunload_handler() {
// Or do something here
}
</script>
Upvotes: 0
Reputation: 1
window.onbeforeunload = ConfirmExit;
function ConfirmExit()
{
return "closed....";
}
Upvotes: 0
Reputation: 927
$( window ).unload(function() {
return "Bye now!";
});
more here https://api.jquery.com/unload/
Upvotes: 1