Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cookies are keeping my CSS from loading... plz help!

Status
Not open for further replies.

beeej21

Technical User
Jul 7, 2003
67
US
Hi all,
I was just referred to this part of the forum from the CSS section. I had thought it was a CSS loading issue that was keeping my page from displaying the proper CSS style. But as it turns out, I've been advised that it is a cookie issue. First time visitors to my main page will see the style loaded correctly. However, upon subsequent visits to the same page, the CSS style doesn't load. If I clear my cookies, I can visit the page again and see the style loaded correctly.
Can someone please tell me how to get my main page to load correctly every time? I am trying to incorporate a CSS style switcher.


Here's the website that I got the CSS style switcher code from:


They have an example here:
Here are the pages I am building:


Please click ENTER on the landing page. The page that loads after hitting ENTER does not load the designated CSS after the visitor has already been to the page once.

I am a designer, but not much of a coder. And this CSS/cookie thingie is really starting to wear me down.

I am hoping and praying that someone will have an easy answer for me. I was hoping to have my photography portfolio site completed before the weekend was over. That's not happening now.

Here are the links to the files:




Thanks in advance!
 
The [tt]window.onload[/tt] function defined in your styleswitcher.js file is getting overwritten by the [tt]onload[/tt] attribute you have set in your HTML. So the code to retrieve the chosen stylesheet is never run.

You need to bring all of the functionality that you want executed on page load into one function. For simplicity's sake you could cut what's in the HTML onload and paste it into your javascript.

[sub]Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
[/sub]

Webflo
 
Thanks for the reply dwarfthrower. I tried cutting the onload attributes from my HTML page and putting them into the javascript file. That didn't solve my problem. I even tried cutting it out completely! And that didn't help me either. The browser still refuses to load the CSS when I return to the page.
 
I am not sure if I did a good thing or not. I found this code at the end of my .js file, and decided to try and delete it and see what would happen. Well, as it turns out, deleted that bit of code seems to have done the trick! Now my page loads the CSS file without fail every time in IE, Netscape, and Firefox too! Let's just hope this wasn't an important piece of code that will come back to haunt me later!

Code:
var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top