|
|
Changing CSS Display state on Load (depending on cookie)
|
|
|
|
Mac Elite
Join Date: Sep 2000
Location: 'round the corner
Status:
Offline
|
|
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"
|
|
|
|
|
|
|
|
|
Professional Poster
Join Date: Oct 1999
Location: :ИOITAↃO⅃
Status:
Offline
|
|
This is trivial in PHP; does your host support PHP?
|
|
|
|
|
|
|
|
|
Grizzled Veteran
Join Date: Nov 2003
Location: Hebburn, UK
Status:
Offline
|
|
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
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Sep 2000
Location: 'round the corner
Status:
Offline
|
|
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?
|
|
|
|
|
|
|
|
|
Grizzled Veteran
Join Date: Nov 2003
Location: Hebburn, UK
Status:
Offline
|
|
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
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Sep 2000
Location: 'round the corner
Status:
Offline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|