View Full Version : How do I only run script on 1st visit?

12-19-2005, 09:16 PM
I just put a little javascript on my website to launch a small mailinglist subscription box when users visit the page. How would I go about setting it so it only loads on the first visit or so it stops loading once they sign up? I'm willing to figure out the code on my own, but I need someone to point me in the right direction.


12-20-2005, 05:55 AM
This is not something that javascript is well suited to. A javascript cookie is the closest thing available but isn't robust enough for this purpose. What kind of mailing list is this? If it is a server based list with a server based program, a way should be able to be devised to do this server side in a much more robust manner than javascript can accomplish.

12-20-2005, 01:45 PM
The mailing list is a cgi script, but that's unrelated to the pop up window, it just has some content (form with a text entry box) in the window.

When visitors go to the main page of my site, the smaller window pops up. I'm just trying to not be too annoying by having it pop up every time they go back to the home page. Even if I could make it do it just once a session that would be good. Can javascript handle that? If not I guess I'll just have to accept being annoying. :D

If you want to see for yourself what I'm talking about - www.ahdchild.com

12-20-2005, 04:04 PM
I get the picture. A javascript cookie would make a good session only check for something like that. Cookies are a little tricky but there have been several 'units' (a grouping of functions that do the hard part for you) written that make them a breeze. One such 'unit' can be found on this page (http://www.quirksmode.org/js/cookies.html) along with an explanation of the use of the unit and principals involved. The unit itself is at the middle of the page. Let me know if you need help implementing it.

12-20-2005, 05:01 PM
That is exactly what I was looking for. Thanks so much