deejaybet Posted December 7, 2005 Share Posted December 7, 2005 (edited) hey all... can any of you help me... ive a script that when the user enters the site a popup appears askin for there name... the user enters there name... i need to make the name appear all the time on the site instead of askin the person there name everytime they enter the site... do you think that entering the name of the visitor is annoying please tell me or can someone help me make a cookie version of the following script: <head><script LANGUAGE="Javascript">var namePrompt = prompt("Who are you?","");if (namePrompt == null || namePrompt == "") namePrompt = "Web Surfer";function dispname (namePrompt) { document.write(""+namePrompt+"");}</SCRIPT></head><body><script LANGUAGE="JavaScript">datetoday = new Date();timenow=datetoday.getTime();datetoday.setTime(timenow);thehour = datetoday.getHours();if (thehour > 18) display = "Evening";else if (thehour >12) display = "Afternoon";else display = "Morning";var greeting = ("<font face='Verdana'>Good " + display + "!");document.write(greeting);document.write(" Thanks for visiting, ");dispname(namePrompt);document.write("!</font>");</SCRIPT></body></head> -----------------Changed to [codebox] to save scroll... Edited January 12, 2006 by Jonas Link to comment Share on other sites More sharing options...
maelstorm Posted December 7, 2005 Share Posted December 7, 2005 Create a cookie:document.cookie = 'myCookie=' + nameprompt +';'Cookies expires: lasts for 7 days.var ckyDate = new Date;ckyDate.setDate(ckyDate.getDate( ) + 7);document.cookie = 'myCookie=' + cookieString + '; expires=' + ckyDate.toGMTString( ) + ';';For over all idea http://www.w3schools.com/js/js_cookies.asp Link to comment Share on other sites More sharing options...
deejaybet Posted December 7, 2005 Author Share Posted December 7, 2005 do a just add that to the script ? Link to comment Share on other sites More sharing options...
deejaybet Posted December 7, 2005 Author Share Posted December 7, 2005 ok im workin wif it and im not gettin it to work properly lol can anyone help me... i want to create a cookie that stores the visitors name and greets the visitor according to the time of day it is...E.g.Good evening "visitor name", thanks for visiting Link to comment Share on other sites More sharing options...
Chocolate570 Posted December 7, 2005 Share Posted December 7, 2005 (edited) Overall code, i used the w3schools js example: <html><head><script type="text/javascript">function getCookie(c_name){if (document.cookie.length>0){ c_start=document.cookie.indexOf(c_name + "=")if (c_start!=-1){ c_start=c_start + c_name.length+1 c_end=document.cookie.indexOf(";",c_start)if (c_end==-1) c_end=document.cookie.lengthreturn unescape(document.cookie.substring(c_start,c_end))} }return null}function setCookie(c_name,value,expiredays){var exdate=new Date()exdate.setDate(expiredays)document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : "; expires="+exdate)}function checkCookie(){username=getCookie('username')if (username!=null) {datetoday = new Date();timenow=datetoday.getTime();datetoday.setTime(timenow);thehour = datetoday.getHours();if (thehour > 18) display = "Evening";else if (thehour >12) display = "Afternoon";else display = "Morning";alert('Good '+display+' '+username+'!')}else { username=prompt('Please enter your name:',"") if (username!=null||username!="") { setCookie('username',username,365) } }}</script></head><body onLoad="checkCookie()"></body></html> -codebox Edited January 12, 2006 by Jonas Link to comment Share on other sites More sharing options...
deejaybet Posted December 8, 2005 Author Share Posted December 8, 2005 ok ive put the script on the test area of my site... only one problem... how do i have the writin appear on the page... it asks for the name but it says good (time of day) (visitor name) as a popup but i want it on the pagehttp://www.layer2hosting.com/~idesign/Philipworld/test/Guest Greeting.htmthe script in actionhttp://www.layer2hosting.com/~idesign/Phil...ages/index2.htmkinda the way i want the script to work in the middle of the page under the header it wer it says Good Morning. Welcome to Philipworld.i want to the script to do the same job but look like Good Morning, (visitor). Welcome to Philipworld. Link to comment Share on other sites More sharing options...
Chocolate570 Posted December 8, 2005 Share Posted December 8, 2005 (edited) Easy. Put this code in the place you want the words to appear: <html><head><script type="text/javascript">function getCookie(c_name){if (document.cookie.length>0){c_start=document.cookie.indexOf(c_name + "=")if (c_start!=-1){c_start=c_start + c_name.length+1c_end=document.cookie.indexOf(";",c_start)if (c_end==-1) c_end=document.cookie.lengthreturn unescape(document.cookie.substring(c_start,c_end))}}return null}function setCookie(c_name,value,expiredays){var exdate=new Date()exdate.setDate(expiredays)document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : "; expires="+exdate)}function checkCookie(){username=getCookie('username')if (username!=null) {datetoday = new Date();timenow=datetoday.getTime();datetoday.setTime(timenow);thehour = datetoday.getHours();if (thehour > 18) display = "Evening";else if (thehour >12) display = "Afternoon";else display = "Morning";document.getElementById("thing").innerHTML='Good '+display+' '+username+'!'}else { username=prompt('Please enter your name:',"") if (username!=null||username!="") { setCookie('username',username,365) } }}</script></head><body onLoad="checkCookie()"></body></html> -codebox Edited January 12, 2006 by Jonas Link to comment Share on other sites More sharing options...
deejaybet Posted December 8, 2005 Author Share Posted December 8, 2005 thank you very much works a treat now Link to comment Share on other sites More sharing options...
Chocolate570 Posted December 8, 2005 Share Posted December 8, 2005 No problem, don't hesitate to ask your next question. ~Chocolate570 Link to comment Share on other sites More sharing options...
deejaybet Posted January 12, 2006 Author Share Posted January 12, 2006 ok i had the user greeting workin on an old server as a test page but now my sites on the new server im havin problems.. user doesnt enter name works ok.. displays null.. dnt mind dat... but wen user enters name it doesnt show the greetin...site page here: http://www.philipworld.kjwebhosting.co.uk/index2.htm 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