...

View Full Version : Personalised welcome message



Harley
07-04-2006, 06:53 PM
I'm coding a HTML portfolio for my I.T class at school and I am very new to Javascript. On the home page of the portfolio I have a script that gets viewers to enter there name a get a personal greeting. I have inserted this tag on to my page

Head
<SCRIPT language="JavaScript">
<!--hide
var yourname= prompt('Please enter your name', ' ');

if ( (yourname==' ') || (yourname==null) )
{
yourname="there";
}

//-->
</SCRIPT>

Body

<SCRIPT language="JavaScript">
<!--hide
document.write("<CENTER><H1>Hello, " + yourname + " ! Welcome to

My E-Portfolio! <\/H1><\/CENTER>");

It works fine but I was wondering if its possible for it to just do it the first time a viewer opens the page. Its pretty annoying going back to the home page and getting the prompt to enter your name every time.

Thanks

_Aerospace_Eng_
07-04-2006, 08:24 PM
You will have to setup a cookie to remember the users name. http://www.quirksmode.org/js/cookies.html

Harley
07-04-2006, 09:02 PM
Will this still work even though my portfolio will not be put on the internet? It will be sent away on CD-ROM to an examiner.

_Aerospace_Eng_
07-04-2006, 09:10 PM
Yeah cookies can be set locally or on a server. Personally though I think the prompt is a waste of time. As its the noob javascript thing to do. No offense of course. Unless the examiner will be mainly looking at your JS then I guess it will be okay.

Harley
07-04-2006, 10:23 PM
They will be looking at everything I do so I'm gona put in as much of everything as possible. I have very little JS on the whole thing so I can't really remove it. Thanks for the help btw.

Harley
07-04-2006, 10:34 PM
I probably will get rid of it now, this cookie business is confusing the hell out of me. :S



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum