Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prompting on onLoad only once

Status
Not open for further replies.

lmarshall

MIS
Jun 11, 2002
108
US
Right now I have the prompt command as an onLoad event on my homepage. It prompts for the user's name then uses their name to welcome them to the page. If the user goes to anthor page within the site and the goes back to the homepage they are again prompted for there name and it welcomes them again. Is there any way to only prompt them once when the first come to the homepage???

Thanks

lmarshall
 
You've got three options in client-side JavaScript for passing informaiton among pages:

1. Cookies - learn to write and retrieve cookie information, Cookies can be written to last for the length of the browswer session (temporary cookies - stored in memory) , or for days/months/years (persistent cookies - stored in text file(s)).

2. Frames - Put your entire site into frames, and use a "stationary" frame to store the information and have the other "framed" files read it from there. The information can be stored as long as the user remains on the site; but as soon as they leave, or if they close their browser, all is lost.

3. The Query String - About as short lived as frames. As soon as the user leaves your site, the information is lost.

If you're lookig for something that will remeber week to week, what the user's name is, then Cookies is, I believe, the only way to do it through client-side JavaScript. Of course, other possibilities open up if you look at server-side scripting..........


Hope this helps -- K
 
for the third option. use a script to determine WHERE the person is coming from, and act accordingly. for example, if you only want them to get asked when they come to your site for the first time EVER, you need cookies...but if being asked the first time they come to the homepage and not asked again while navigating your site, then try this:

<script language=&quot;JavaScript&quot;><!--
if (document.referrer.indexOf(yourdomainname.com') < 0)
onLoad &quot;whatever you want it to do here&quot;
--></SCRIPT>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top