Tricky Tricks ›› Programming Tricks ›› Javascript Tricks ›› Way To Post A Message To The First Time Visitor

Way To Post A Message To The First Time Visitor

Javascript Tricks

Is there a way I can welcome a first time visitor to my site, or at least post them a special message?

This little snippet was contributed by Jeremy aka taz97@flash.net whose brother Chad is some sort of computer genius. Thanks for the submission guys.

Well, I should point out that it really is a message for people that have never received your cookie. What's a cookie? It's a small file that gets written to the hard disk. Don't worry, it is not a security problem (so far!).

The person getting your cookie for the first time will get a little message box containing your messages, with an OK prompt to continue. This is a little hard to test as you have to erase your cookies to make it work more than once for you.

In case you missed it, the message looks like this:

Java Alert

To install, just cut and past this code into your HTML
document- just below the <BODY> tag. You can change
the ZZZZZ to be your name or whatever.
Of course, also change the message- just be sure to keep
the ENTIRE message on ONE line!

 <SCRIPT LANGUAGE="JavaScript">
 <!--
 function GetCookie(name) {
   var arg=name+"=";
   var alen=arg.length;
   var clen=document.cookie.length;
   var i=0;
   while (i<clen) {
     var j=i+alen;
     if (document.cookie.substring(i,j)==arg)
       return "here";
     i=document.cookie.indexOf(" ",i)+1;
     if (i==0) break;
   }
   return null;
 }
 var visit=GetCookie("ZZZZZ");
 if (visit==null){
    alert("Your Message Goes here and you only get to see it once!");
    var expire=new Date();
    expire=new Date(expire.getTime()+7776000000);
    document.cookie="ZZZZZ=here; expires="+expire;
 }
 // -->
 </SCRIPT>
 

Sitemap : Partners