I want to ask for a confirmation to the user when they are leaving a page.
I know it can be achieved very easily using javascipt's window.onbeforeunload
But the only issue is, it shows a pop up(see picture) when I reload the page. I don't want to display that pop up upon page reload. I think that pop-up is displaying by the web browser as it shows a message "Do you want to reload this site?" which I have not written anywhere.
Here is my simple code:
<html>
<head>
<title>Script</title>
<script>
window.onbeforeunload = function () {
return 'Are you sure you want to leave?';
};
</script>
</head>
<body>
hello
<a href="http://google.com">Google</a>
</body>
</html>
Any help would be appreciated.
EDIT:
Lots of people saying that it is bad to ask user while he is leaving the site and I'm also completely agreed with that. But it is client's requirement, so it is not up to me. Sorry for that.
Thanks,
Parth vora