Log in

View Full Version : Message on page exit...



rhiaro
06-08-2008, 08:23 PM
All I want is a simple message to appear on the page exit - just to say goodbye etc. I'm sure I've done this before, but couldn't find it anywhere! The closest I got was this script from Javascriptkit: http://www.javascriptkit.com/script/script2/alertmsg.shtml - except that this displays the message on loading the page, not leaving. If anyone can help that would be great... still learning the basics of Javascript, so haven't had much luck understanding what is going on that code so far...

Thanks in advance :)

rangana
06-09-2008, 12:09 AM
<script type="text/javascript">
window.onbeforeunload = function()
{return "Are you sure you want to exit?";}
</script>

traq
06-09-2008, 03:28 AM
cool. could that be modified to show the message only when leaving the domain (and not when leaving the page for another on the same site)?

rangana
06-09-2008, 05:03 AM
cool. could that be modified to show the message only when leaving the domain (and not when leaving the page for another on the same site)?

See if this helps:


<script type="text/javascript">
var domain='http://www.domain.com'; // Set your domain here.
window.onbeforeunload = function()
{
if(this.location.href.indexOf(domain)==-1)
{
return "Are you sure you want to exit?";
}
}
</script>