View Full Version : Using JS To Do A Only Once Option

05-24-2008, 09:05 PM
I am trying to write some JS code that let users access a page only once and only once.

For example

User comes to a page and then click a link to a pop-up
Pop-up has some information, then users close it
If users tries to click the link to the pop-up again
A message comes up that say "Sorry you've already accessed this once"

I'm think I need to set a cookie on the users computer but I just can't get the code.

Thank you.

05-25-2008, 05:28 AM
Javascript cookies are unreliable (the user's browser may refuse them and/or in some cases delete or rewrite them). If this is 'mission critical'*, you would need to work something out on the server side (PHP, asp, or whatever is available on your host in the way of a server side language that supports server side cookies or a variable(s) that can act like cookies). If this isn't 'mission critical', a good explanation of javascript cookies and functions that simplify the use of javascript cookies is here:


*An example of 'mission critical' would be where, if the user took control of the situation, they could do something that would harm you. Like if sales or information that must remain private are involved, etc.