Jump to content

user greeting


deejaybet

Recommended Posts

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 by Jonas
Link to comment
Share on other sites

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

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 by Jonas
Link to comment
Share on other sites

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

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 by Jonas
Link to comment
Share on other sites

  • 1 month later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...