Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Changing CSS Display state on Load (depending on cookie)

Changing CSS Display state on Load (depending on cookie)
Thread Tools
Nebagakid
Mac Elite
Join Date: Sep 2000
Location: 'round the corner
Status: Offline
Reply With Quote
Dec 5, 2004, 11:39 AM
 
So, I would like to have something display when the visitor comes for the first time, but subsequent times it is hidden. How can I achieve this if the ID of the DIV is "helperboy"
     
Mithras
Professional Poster
Join Date: Oct 1999
Location: :ИOITAↃO⅃
Status: Offline
Reply With Quote
Dec 5, 2004, 11:42 AM
 
This is trivial in PHP; does your host support PHP?
     
Chris O'Brien
Grizzled Veteran
Join Date: Nov 2003
Location: Hebburn, UK
Status: Offline
Reply With Quote
Dec 5, 2004, 11:52 AM
 
It's quite easy. Since handling cookies is always the same, I'll just nick webreferences's functions for it. See here for them and to include them.

So, assuming that helperboy has been set to display: none in its CSS we can simply have

Code:
function init() { if (!getCookie('visited')) { document.getElementById("helperboy").style.display = "block"; var now = new Date(); now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000); setCookie('visited','yes',now); } }
and call init() onload.

You'll need to include the functions i linked to aswell. I haven't tested this, but it should work. Oh, the article I linked to is also well worth a read if you want to know about cookies.

Edit: I should note that the time and value of the set cookie are arbitrary. here we're not actually worrying about the value, just wanting to know if the cookie has been set. I chose a year, just because....
Just who are Britain? What do they? Who is them? And why?

Formerly Black Book
     
Nebagakid  (op)
Mac Elite
Join Date: Sep 2000
Location: 'round the corner
Status: Offline
Reply With Quote
Dec 6, 2004, 02:42 AM
 
yeah, i am really lost here, I pasted it all in... and I have no idea why it would not be working.

could you provide me with some more instructions?
     
Chris O'Brien
Grizzled Veteran
Join Date: Nov 2003
Location: Hebburn, UK
Status: Offline
Reply With Quote
Dec 6, 2004, 05:42 AM
 
Originally posted by Nebagakid:
yeah, i am really lost here, I pasted it all in... and I have no idea why it would not be working.

could you provide me with some more instructions?
Can you link to the page you've got so I can take a look?
Just who are Britain? What do they? Who is them? And why?

Formerly Black Book
     
Nebagakid  (op)
Mac Elite
Join Date: Sep 2000
Location: 'round the corner
Status: Offline
Reply With Quote
Dec 10, 2004, 04:26 PM
 
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 08:32 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,