|
Example
The below JavaScript
will make the user currently visiting the site stay on the web page by giving a message to how long they visited the
particular web site as well as opening a new window.
We have mainly placed this script on Computer Hope to look at the source code for ideas
for other possible JavaScript and do not recommend anyone placing this script on their
pages as this irritates the viewers of your web pages.
In addition, as an example, we have placed this code into this page and for you to do the
same you must include this into the beginning of your web page within your head tags,
as well as ending the page with the </body>, once completed.
Source code
<head><script
language="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 envoke 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
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");
// open a new window to play an audio plea.
win = window.open ("under.au","newwin");
}
else {
alert (TIMEON + "Thanks for reading");
win=window.open("http://www.computerhope.com","newwin");
}
return true;
}
</script>
<title></title>
</head>
<body onload="getStime()" ;
onUnload="figure()" ; TEXT="#000040" LINK="#268999"
VLINK="#FF0000" ALINK="#FFFF00">
</body> |