1

I need help writing a persistent stylesheet switcher. I have found an article on ALA but for whatever reason I cannot get it to work!

I have three stylesheets, the default one for the layout and another two which the user will switch between (adjusting the colours). I may later add one for print but I am not there yet.

The style switcher javascript file can be found here http://www.alistapart.com/d/alternate/styleswitcher.js

I have this in the <head> of my page at the moment.

<script type="text/javascript" src="js/styleswitcher.js"></script>
<link rel="stylesheet" type="text/css" href="css/style.css" />
<link rel="alternate stylesheet" type="text/css" href="css/alt_style1.css" title="purple" />
<link rel="alternate stylesheet" type="text/css" href="css/alt_style2.css" title="red" />

I want the user's selection to be stored in a cookie so that it can be remembered.

The links that select the different stylesheets, in my <body> tag look like this.

<a href="#" onclick="setActiveStyleSheet('purple'); return false;">purple</a>
<a href="#" onclick="setActiveStyleSheet('red'); return false;">red</a>

I really don't know what I am doing wrong. The stylesheet doesn't change. See it in action here - or not as the case is!

http://uni.michaelnorris.co.uk/

w0lf42
  • 508
  • 6
  • 19
Michael
  • 4,282
  • 9
  • 55
  • 89
  • Are both stylesheets applied? or just the style2 styles applied? – mqsoh Nov 01 '11 at 15:40
  • Originally I had the default 'style.css' stylesheet and the alternate 'alt_style1.css' stylesheet, but I added a truly persistent stylesheet and two others which just alternate with colours. All that happens is that nothing changes. – Michael Nov 01 '11 at 15:42
  • The link you added works fine for me in Firefox 7.0.1 on Linux. – mqsoh Nov 01 '11 at 15:46
  • Shouldn't this work in Safari then? That is what I am using. I have just tested it in Firefox and it works... So why not in Safari? Another note, how can I make the style.css be persistent, and just switch the alternate ones? – Michael Nov 01 '11 at 15:47
  • The link you provided has no alternate stylesheets at the moment. If you still need your question answered please update the link, or make a jsfiddle/jsbin test case. – vinczemarton Mar 17 '13 at 10:52

0 Answers0