Help make people stay on your page

Updated: 09/07/2019 by Computer Hope

The JavaScript below helps keep the visitor on the web page by displaying a message of how long they visited the page.

We have mainly placed this script on Computer Hope to look at the source code for ideas of other possible JavaScript. We do not recommend anyone placing this script on your web pages, as this irritates the viewers of your web pages.

Also, as an example, we have placed this code on our example page. For the code to work on your page, place it in the head tags.

Warning

The JavaScript code below does not work in the latest versions of modern Internet browsers.

Example source code

<head><script type="text/javascript">
// This script was written by Kurt A>
//http://www.geocities.com/soho/lofts/1238
// I only ask that you leave this plug to my page if you use the script.
// It worked for me, If it works for anyone else ----- I can't say.
// It times the user for a page and gives a response dependant on the
// duration of the visit to the page.
// It doesn't work well with the #links because anytime a back button
 //is hit the script will invoke itself
var STS = 0;
var ETS = 0;
var TIMON = 0;
function getStime() {
// optional audio welcome
// location = "welcome.au";
now = new Date();
STS = (now.getTime());
// optional.
// changes the window status bar at bottom of page return true must remain
// Only works if user allows JavaScript to change his/her status bar text
//window.status = "I hope you enjoy"; return true ;
}
function figure() {
// code to get seconds from logon to logoff
postnow = new Date();
ETS = (postnow.getTime());
TIMEON = ((ETS - STS) / 1000);
// if less than 60 seconds
if (TIMEON < 60) {
// open an alert box and plead with user
alert ( TIMEON + " seconds. Give it a chance!");
// Optional - open a new window to play an audio plea.
//window.open ("under.au","newwin","width=200, height=200");
}
else {
alert (TIMEON + " seconds. Thanks for reading!");
}
return true;
}
window.onload = getStime;
 window.onunload = figure;
</script>
<title></title>
</head>