Javascript - Showing a goodbye message to visitors

April 2018

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!");

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).
Published by netty5. Latest update on November 6, 2016 at 02:37 PM by owilson.
This document, titled "Javascript - Showing a goodbye message to visitors," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (
Javascript libraries (Prototype/ Scriptaculous/ Yahoo UI, etc.).
Ajax - Javascript - Multiple upload