autasebo Posted October 16, 2006 Share Posted October 16, 2006 I want to create some Javascript code that will set a cookie the first time a user comes and displays "Welcome", and then displays "Welcome back. Your last visit was on" + date last at site when the user returns to the page. No pop-ups to ask the users name. Thanks!!!P.S. Anyone with working cookie code is greatly praised!! Link to comment Share on other sites More sharing options...
jesh Posted October 16, 2006 Share Posted October 16, 2006 Have you looked at the Javascript Cookie Tutorial? Link to comment Share on other sites More sharing options...
autasebo Posted October 17, 2006 Author Share Posted October 17, 2006 I have, but I can't figure out how to get rid of the alert and set it up to record the time. I'm new to Javascript so any help is..... helpful!! Link to comment Share on other sites More sharing options...
jesh Posted October 17, 2006 Share Posted October 17, 2006 Where you able to follow along with the tutorial so that a cookie was being written to your computer? If so, you can store the current date as the value of the cookie rather than the "username" and call the cookie something like "LastVisit".The new "checkCookie" function could look like this: function checkCookie(){ // we'll use displaytext to display the text to the screen. var displaytext = "Welcome"; // here we try to get the cookie. lastvisit = getCookie("LastVisit"); if(lastvisit != null) { // we found the cookie. Let's add some more text to our message displaytext += " back. Your last visit was on " + lastvisit; } else { // there wasn't a cookie, let's set one and assign the current date as the value. setCookie("LastVisit", new Date(), 365) } // now we'll write the message to the screen. document.write(displaytext);} For more elaborate ways to get the text displayed to the screen, I would suggest looking at the HTML DOM Tutorial and learn about the "innerHTML" property. Link to comment Share on other sites More sharing options...
jhecht Posted October 18, 2006 Share Posted October 18, 2006 jesh pretty much nailed it on the head,if you need to you could set the cookie witht he unix timestamp of the time they visited and then use Js's DATE object to get the variables from there, but hey your choice. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now