Javascript - Showing a goodbye message to visitors

Ask a question




It is sometimes very nice to display a message thanking your visitors for their visit. This tip is designed to show you how.

The JavaScript

Copy and paste this code between the <head> </ head> of your html page

<script language="javascript"> 
function bye()
{
// modify text to your needs
alert ("Thank you for your visit!");
}
</script>

Calling the Script

To use this feature, simply add the onunload event in the <body>

<body onUnload="bye();">

Note that

  • This is to be made on all pages of your site.
  • Many users no more appreciate such "intrusion", so used sparingly (imagine a news site with such a message ... and it pop-up "10-100 times a day).
Jean-François Pillou

CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jeff Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.

Learn more about the CCM team