Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    New Coder
    Join Date
    Oct 2006
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Display time of last visit script

    I have just inserted the "Display time of last visit script" from JavaScriptKit.com on my site. Instead of displaying the last visit time the script shows the current time of each visit. What is my error ? Thanks

    PS: obviously the script works well at http://www.javascriptkit.com/script/...astvisit.shtml

  • #2
    New Coder TripperTreats's Avatar
    Join Date
    Oct 2006
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Did you copy the script verbatim from the site?
    Do you use cookies in any other way on your site?
    Psychedelic digital art at www.trippertreats.com.

    "And in the end, the love you take
    is equal to the love you make
    ."

  • #3
    New Coder
    Join Date
    Oct 2006
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yes de script was copy directly from site and cookies are not used in other way. Thanks

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,898
    Thanks
    203
    Thanked 2,530 Times in 2,508 Posts
    Check again carefully to make sure you have not accidentally deleted or changed anything in the script.

  • #5
    New Coder
    Join Date
    Oct 2006
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Just repeat all operation, starting copy script from source and build a new test page. Problem remains ... The test page is located at http://www.carnaxidedigital.com/welcome.html. Thanks

  • #6
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I went the first time and it said something like welcome new user.

    The next time it said

    Welcome back visitor! Your last visit was on Saturday, January 13, 2007 3:00:28 PM

    Is this fixed or am I misunderstanding the problem?

    david_kw

  • #7
    New Coder
    Join Date
    Oct 2006
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The issue is the date/time showed is no the last visit time but the current time...

  • #8
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ahh I misread your initial post.

    Well the real problem was the cookie didn't save the time when someone logged in so there was no way to get it back. It looks like the original code was to count how many times you have visited. So instead of saving that, I changed it to save the time you visited so that could be printed instead of the current time.

    I put in some alerts so you can see what it is doing and I had to put some whitespace in the code so I could read it more easily.

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>
    
    <body><script type="text/javascript">
    
    /***********************************************
    * Display time of last visit script- by JavaScriptKit.com
    * This notice MUST stay intact for use
    * Visit JavaScript Kit at http://www.javascriptkit.com/ for this script and more
    ***********************************************/
    
    var lastvisit=new Object();
    lastvisit.firstvisitmsg="This is your first visit to this page. Welcome!" //Change first visit message here
    lastvisit.subsequentvisitmsg="Welcome back visitor! Your last visit was on <b>[displaydate]</b>" //Change subsequent visit message here
    
    lastvisit.getCookie=function(Name){ //get cookie value
      var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
      if (document.cookie.match(re)) { //if cookie found
        return document.cookie.match(re)[0].split("=")[1]; //return its value
      }
      return "";
    }
    
    lastvisit.setCookie=function(name, value, days){ //set cookei value
      var expireDate = new Date();
      //set "expstring" to either future or past date, to set or delete cookie, respectively
      expireDate.setDate(expireDate.getDate()+days);
      var expstring=expireDate.toGMTString();
      alert("expires = " + expstring);
      document.cookie = name+"="+value+"; expires="+expstring+"; path=/";
    }
    
    lastvisit.showmessage=function(){
      var ldate = lastvisit.getCookie("visitcounter");
      if (ldate==""){ //if first visit
        document.write(lastvisit.firstvisitmsg);
      } else {
        document.write(lastvisit.subsequentvisitmsg.replace("\[displaydate\]", ldate));
      }
      lastvisit.setCookie("visitcounter", new Date().toLocaleString(), 730); //set "visitcounter" to today's date and for 730 days (2 years)
    }
    
    lastvisit.showmessage()
    alert("current time = " + new Date().toLocaleString());
    
    </script>
    </body>
    </html>
    david_kw

  • #9
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,898
    Thanks
    203
    Thanked 2,530 Times in 2,508 Posts
    Quote Originally Posted by arturex View Post
    I have just inserted the "Display time of last visit script" from JavaScriptKit.com on my site. Instead of displaying the last visit time the script shows the current time of each visit. What is my error ? Thanks

    PS: obviously the script works well at http://www.javascriptkit.com/script/...astvisit.shtml
    David - this had me baffled as the javascriptkit script and that of arturex are identical. How come it works at javascriptkit?

  • #10
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Apparently they aren't using their own code. Notice the message the webpage gets is

    Welcome back. Your last visit was on Sun, Jan 14 2007 at 10:51

    But the code says it should be

    Welcome back visitor! Your last visit was on <b>[displaydate]</b>

    The code they have to write the date on the webpage is

    Code:
    if (Count()==1){
      document.write("This is your 1st visit to our page")
      When()
    }
    else if (Count()>1)
      document.write("Welcome back. Your last visit was on <b>" + When() +"</B>.")
    Which is completely different from what the code is they say to copy and paste. I've never used javascriptkit before. Is this an unusual case?

    david_kw

  • #11
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,898
    Thanks
    203
    Thanked 2,530 Times in 2,508 Posts
    Ah ha! Mystery solved!! I have to say that I have never encountered this before with any source, and always assumed that the demo was the same as the offered script. Perhaps a mod should look into this.

  • #12
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here is the actual code used on the javascriptkit page

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    <script type="text/javascript">
    <!-- Begin Script
    
    //Display Time of last visit script- Mattias Sjoberg
    //Modified by JavaScript Kit (http://javascriptkit.com)
    //Visit http://javascriptkit.com for this script
    
    var expDays = 30;
    var exp = new Date(); 
    exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
    
    function When(info){
    	// When
    	    	var rightNow = new Date()
    		var WWHTime = 0;
    		WWHTime = GetCookie('WWhenH')
    		
    		WWHTime = WWHTime * 1
    
    		var lastHereFormatting = new Date(WWHTime);  // Date-i-fy that number
    	        var intLastVisit = (lastHereFormatting.getYear() * 10000)+(lastHereFormatting.getMonth() * 100) + lastHereFormatting.getDate()
    	        var lastHereInDateFormat = "" + lastHereFormatting;  // Gotta use substring functions
    	        var dayOfWeek = lastHereInDateFormat.substring(0,3)
    	        var dateMonth = lastHereInDateFormat.substring(4,10)
    		var hours = "" + lastHereFormatting.getHours()
    		var year = lastHereFormatting.getYear()
                    if (year < 1000) year+=1900
    		var minutes = "" + lastHereFormatting.getMinutes()
    		if (minutes.substring(0,1) == minutes){
    			minutes = "0" + minutes
    		}
    	        var WWHText = dayOfWeek + ", " + dateMonth + " " + year + " at " +  hours + ":" + minutes// display
    	
    		SetCookie ("WWhenH", rightNow.getTime(), exp)
    
    	return WWHText;
    }
    
    function Count(info){
    	var psj=0;
    	// How many times
    		var WWHCount = GetCookie('WWHCount')
    		if (WWHCount == null) {
    			WWHCount = 0;
    		}
    		else{
    			WWHCount++;
    		}
    		SetCookie ('WWHCount', WWHCount, exp);
    
    
    	return WWHCount+1;
    }
    
    
    
    function set(){
    //	VisitorName = prompt("Who are you?", "Nada");
    //	SetCookie ('VisitorName', VisitorName, exp);
    	SetCookie ('WWHCount', 0, exp);
    	SetCookie ('WWhenH', 0, exp);
    }
    
    function getCookieVal (offset) {  
    	var endstr = document.cookie.indexOf (";", offset);  
    	if (endstr == -1)    
    		endstr = document.cookie.length;  
    		return unescape(document.cookie.substring(offset, endstr));
    }
    
    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 getCookieVal (j);    
    		i = document.cookie.indexOf(" ", i) + 1;    
    		if (i == 0) break;   
    	}  
    	return null;
    }
    
    function SetCookie (name, value) {  
    	var argv = SetCookie.arguments;  
    	var argc = SetCookie.arguments.length;  
    	var expires = (argc > 2) ? argv[2] : null;  
    	var path = (argc > 3) ? argv[3] : null;  
    	var domain = (argc > 4) ? argv[4] : null;  
    	var secure = (argc > 5) ? argv[5] : false;  
    	document.cookie = name + "=" + escape (value) + 
    	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
    	((path == null) ? "" : ("; path=" + path)) +  
    	((domain == null) ? "" : ("; domain=" + domain)) +    
    	((secure == true) ? "; secure" : "");
    }
    
    function DeleteCookie (name) {  
    	var exp = new Date();  
    	exp.setTime (exp.getTime() - 1);  
    	// This cookie is history  
    	var cval = GetCookie (name);  
    	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
    
    }
    //  End Script -->
    </script>
    </head>
    
    <body>
    <script>
    if (Count()==1){
    document.write("This is your 1st visit to our page")
    When()
    }
    else if (Count()>1)
    document.write("Welcome back. Your last visit was on <b>" + When() +"</B>.")
    </script>
    </body>
    </html>
    david_kw

  • #13
    New Coder
    Join Date
    Oct 2006
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks to all people, for the help.

  • #14
    New Coder
    Join Date
    Oct 2006
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I still need a minor change - with the correct version of script the date is not showed in local language (and the bug version does). What need to be changed. Thanks, once more.

  • #15
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It looks like the "correct" script does it's own formatting of the date. If you want it to be the Locale version then just look at the function When() and strip out anything to do with formatting the date.

    The easy way is to make this change to the end of When()

    Code:
      return lastHereFormatting.toLocaleString();
    //	return WWHText;
    That will leave in the old formatting code in case you want to go back to it.

    david_kw


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •