How can I detect if a user has any intention to leave his current page and redirect to any page from my website is their any javascript function that can handle this event I have more than 25 links in my page
<script type="text/javascript">
if(//user clicks a link )
confirm("do you want to continue ?");
</script>
Is their any javascript function that can check if the user click on any link on the page
This code will intercept all clicks on links in your page.
FYI, unless there are very special circumstances in your page, it’s kind of obnoxious to force a user to confirm that they actually want to go to the link they just clicked on. Can you imagine how terrible the web browser would be if you had to confirm every click.
There is also a generic way to prompt if the user wants to leave your page using the
onbeforeunloadevent.Note: this is also obnoxious unless there are very special circumstances.