user317005
user317005

Reputation:

dialog, when "x" clicked hide forever (javascript)

so, when a user visits the site for the first time i want to show a dialog box, and when the user clicks "x" or "hide" i want to hide it from that user forever.

this only works with cookies, right?

so, when the user clears his/her cookies he/she will see the dialog box again, next time they visit the site, i assume.

or is there a better/more common way to do this?

Upvotes: 0

Views: 257

Answers (5)

zzzzBov
zzzzBov

Reputation: 179086

Cookies are the correct answer to persistent state, but it's not a bulletproof solution.

What if a user visits your site on one computer, and then visits again from a different computer? They'll see the message twice. Usually in cases such as these I recommend rethinking your approach.

  • What is the purpose of the dialog?
  • Is there a reason the user shouldn't see it a second time?
  • Can it be placed elsewhere in the page for the same/better effect?

If you really want to be nasty with cookies, you can look at evercookie. But please only use your powers for good or for awesome.

Upvotes: 0

PseudoNinja
PseudoNinja

Reputation: 2856

Create a user_properties table add column "firstTimeDialog" (or isVirgin) as SMALLINT with default value of '1'. when user clicks box send AJAX call to server-side to change the value to 0. Load user properties with user information into the session on login and you a very simple way of checking to see if its a users first time.

Remember a users first time should be memorable, so be gentle.

Upvotes: 0

Samo
Samo

Reputation: 8240

Can you store a property on the user? It can be false by default and when you click the 'x' you can make an AJAX call that sets it to true. Your dialog box could key off this property...

This way you wouldn't have to worry about the scenario where the user clears the cookies. Of course it will only work if you have user objects server side and it is storing extra data to overcome a very small problem, so it might not be goood practice. Just an idea.

Upvotes: 1

Neil
Neil

Reputation: 5780

No, nor should there be. Cookies are the only means for a site to retain information. Allowing a site to do anything more is a serious breach in security.

Upvotes: 1

John Giotta
John Giotta

Reputation: 16964

This is a fairly common approach to stored state.

Upvotes: 0

Related Questions