PDA

View Full Version : Display alert when close the browser window



ponnithya
12-24-2009, 06:14 AM
Hi,
I need to display alert when I close the browser window. Now I am using the following code to display the alert. But the alert is getting displayed even I click on any links. But the alert should not displayed when i click the link.

If you have any solution, please let me know.

Thanks in advance.


This is my code:

<HTML>

<head>

<script>

function closeIt()

{

return "";

}

window.onbeforeunload = closeIt;

</script>

</head>

<body>

<a href="http://www.test.com">Click here to navigate to

www.test.com</a>

</body>

</html>

Philip M
12-24-2009, 08:58 AM
Try this:-



<script type = "text/javascript">
var ClosingVar = true;
var message = "This is the bespoke message";
window.onbeforeunload = ExitCheck;
function ExitCheck() {
if (ClosingVar == true) {
ExitCheck = false
return message;
}
}
</script>

<a href="http://www.mysite.com" onClick="ClosingVar=false">Go to another page</a>

Remember that the window.onbeforeunload event is fired every time the page is about to unload. This means that if the user clicks "refresh" or a button on your page, and your page posts back to the server, the window.onbeforeunload event will fire.

This sort of prompt tends to annoy the user, and should be avoided unless it really adds value.

Please read the forum rules and posting guidelines. And remove unnecessary white space.


All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.