CSS Stylesheet Switcher Problems

This is a discussion on "CSS Stylesheet Switcher Problems" within the JavaScript Forum section. This forum, and the thread "CSS Stylesheet Switcher Problems are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Dec 18th, 2007, 19:32
Jack Franklin's Avatar
Resources Administrator

SuperMember
Join Date: May 2007
Location: Cornwall, England
Posts: 1,268
Blog Entries: 7
Thanks: 10
Thanked 4 Times in 4 Posts
CSS Stylesheet Switcher Problems

Hey guys,

Attempting to use a stylesheet switcher which I downloaded off here:
http://www.alistapart.com/stories/alternate/

I have this code in the 'Head' of each .html page.
Code: Select all
<link rel="stylesheet" type="text/css" href="mainstylexmas.css" title="xmas" />
<link rel="alternate stylesheet" type="text/css" href="mainstyle.css" title="default" />
<script type="text/javascript" src="styleswitcher.js"></script>
And this is the javascript:
Code: Select all
function setActiveStyleSheet(title) {
var i, a, main;
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
a.disabled = true;
if(a.getAttribute("title") == title) a.disabled = false;
}
}
}
function getActiveStyleSheet() {
var i, a;
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
}
return null;
}
function getPreferredStyleSheet() {
var i, a;
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
if(a.getAttribute("rel").indexOf("style") != -1
&& a.getAttribute("rel").indexOf("alt") == -1
&& a.getAttribute("title")
) return a.getAttribute("title");
}
return null;
}
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
window.onload = function(e) {
var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
}
window.onunload = function(e) {
var title = getActiveStyleSheet();
createCookie("style", title, 365);
}
var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
The strange thing is, it works fine testing locally on my PC (In IE7, IE6 & FF2), but does not work once uploaded in any browser.

The address is jackfranklin.co.uk.

Thank you,

Jack
Last Blog Entry: My Latest Project - Grilling Gurus... (Jun 11th, 2008)

Last edited by Jack Franklin; Dec 18th, 2007 at 19:34.
Reply With Quote

  #2 (permalink)  
Old Dec 18th, 2007, 19:36
Marc's Avatar
Moderator

SuperMember
Join Date: Apr 2007
Location: Scotland, UK
Age: 15
Posts: 1,649
Thanks: 0
Thanked 8 Times in 8 Posts
Send a message via MSN to Marc Send a message via Skype™ to Marc
Re: CSS Stylesheet Switcher Problems

Hey,

I dont know why this could happen.. Mabey try clearing your cache?

Even better, you might want to use a PHP one that was in the newsletter: Creatve Coding: Dynamic Stylesheet Switcher.

Just an idea that might be better .
Reply With Quote
  #3 (permalink)  
Old Dec 18th, 2007, 19:56
Jack Franklin's Avatar
Resources Administrator

SuperMember
Join Date: May 2007
Location: Cornwall, England
Posts: 1,268
Blog Entries: 7
Thanks: 10
Thanked 4 Times in 4 Posts
Re: CSS Stylesheet Switcher Problems

Marc,

That did no good. However, I managed to follow that PHP tutorial you referenced me - and now it all works perfectly. Thanks.

If anyone does have a solution to the javascript problem, I would love to hear it out of curiosity.

Jack
Last Blog Entry: My Latest Project - Grilling Gurus... (Jun 11th, 2008)
Reply With Quote
  #4 (permalink)  
Old Dec 18th, 2007, 20:01
Marc's Avatar
Moderator

SuperMember
Join Date: Apr 2007
Location: Scotland, UK
Age: 15
Posts: 1,649
Thanks: 0
Thanked 8 Times in 8 Posts
Send a message via MSN to Marc Send a message via Skype™ to Marc
Re: CSS Stylesheet Switcher Problems

Glad I was able to assist you! Oh and the PHP way is better as all users will see it, unlike users that have JavaScript disabled.
Reply With Quote
  #5 (permalink)  
Old Dec 18th, 2007, 20:09
Jack Franklin's Avatar
Resources Administrator

SuperMember
Join Date: May 2007
Location: Cornwall, England
Posts: 1,268
Blog Entries: 7
Thanks: 10
Thanked 4 Times in 4 Posts
Re: CSS Stylesheet Switcher Problems

Yes, I knew that, but have always used javascript switchers! I would give you rep but I can't find the rep button?
Last Blog Entry: My Latest Project - Grilling Gurus... (Jun 11th, 2008)
Reply With Quote
  #6 (permalink)  
Old Dec 18th, 2007, 20:10
Marc's Avatar
Moderator

SuperMember
Join Date: Apr 2007
Location: Scotland, UK
Age: 15
Posts: 1,649
Thanks: 0
Thanked 8 Times in 8 Posts
Send a message via MSN to Marc Send a message via Skype™ to Marc
Re: CSS Stylesheet Switcher Problems

There isn't one anymore . It was switched off.
Reply With Quote
  #7 (permalink)  
Old Dec 18th, 2007, 20:23
Jack Franklin's Avatar
Resources Administrator

SuperMember
Join Date: May 2007
Location: Cornwall, England
Posts: 1,268
Blog Entries: 7
Thanks: 10
Thanked 4 Times in 4 Posts
Re: CSS Stylesheet Switcher Problems

No! How come?
Last Blog Entry: My Latest Project - Grilling Gurus... (Jun 11th, 2008)
Reply With Quote
  #8 (permalink)  
Old Dec 18th, 2007, 21:48
Reputable Member
Join Date: Apr 2007
Location: Scotland
Age: 17
Posts: 233
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Blake121
Re: CSS Stylesheet Switcher Problems

Yeah... That's one hell of a good article in the newsletter.

Complete genius.
Reply With Quote
  #9 (permalink)  
Old Dec 19th, 2007, 06:42
Jack Franklin's Avatar
Resources Administrator

SuperMember
Join Date: May 2007
Location: Cornwall, England
Posts: 1,268
Blog Entries: 7
Thanks: 10
Thanked 4 Times in 4 Posts
Re: CSS Stylesheet Switcher Problems

I agree who made that then?

I seem to remember it was one of the annoying ones...

:P

Thanks Blake, really good article
Last Blog Entry: My Latest Project - Grilling Gurus... (Jun 11th, 2008)
Reply With Quote
  #10 (permalink)  
Old Dec 19th, 2007, 07:24
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,608
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Send a message via Yahoo to Monie
Re: CSS Stylesheet Switcher Problems

I used this: CSS Style Switcher
Check out the real time example, and step by step guide for you!
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)
Reply With Quote
  #11 (permalink)  
Old Dec 19th, 2007, 07:32
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,608
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Send a message via Yahoo to Monie
Re: CSS Stylesheet Switcher Problems

Quote:
Originally Posted by Blake121 View Post
Yeah... That's one hell of a good article in the newsletter.

Complete genius.
Yeah, you are genius Blake
Pride
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)
Reply With Quote
  #12 (permalink)  
Old Dec 19th, 2007, 10:39
Reputable Member
Join Date: Apr 2007
Location: Scotland
Age: 17
Posts: 233
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Blake121
Re: CSS Stylesheet Switcher Problems

Haha.

Cheers guys.
Reply With Quote
  #13 (permalink)  
Old Dec 21st, 2007, 00:23
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,608
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Send a message via Yahoo to Monie
Re: CSS Stylesheet Switcher Problems

Just jocking Blake
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)
Reply With Quote
Reply

Thread Tools

Posting 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
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Vanishing stylesheet galan98 Web Page Design 6 Jul 9th, 2007 15:48
Possible to detect which stylesheet in use? mar2195 JavaScript Forum 9 Nov 25th, 2006 11:43
ASP stylesheet switcher with conditional comments Shelly Classic ASP 1 Apr 19th, 2006 12:44
having problems passing parameters to xsl stylesheet from javascript zzqproject Other Programming Languages 2 Nov 22nd, 2005 10:46


All times are GMT. The time now is 22:41.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43