If you're seeing this announcement, you don't have a stylesheet selected to view this site, or your stylesheet is due to be discontinued. Please use the Style Switcher to choose a viewing style.
retro | blue rain | excess baggage | sexed up
THIS IS THE OLD SITE!

Feel free to browse in here if you feel that there is something here that is not on the new site, but these sections will no longer be updated - and will soon be deleted.

Please come to our new section found here - and don't forget to update your bookmarks and links.
You are here: ezdesign » masterclasses » style switcher
May 02, 2004
style switcher
Set your board or site up to have a choice of looks using css, and let your visitors select their preference with this style switcher.

by atlass
Setting up a style switcher is pretty easy, all you need is a javascript file, some css files and a bit of code for your visitors to click and choose their style.

So here's what you do - first off, I suggest you create your stylesheets. If you're doing this for your ezboard, then create them in the board so you can see how they look. You need at least two, obviously. When you've done that, upload them to your own webhost and get the urls. Yes, you need a webhost.

Let's assume you have a choice of three stylesheets - the code to link to them will look like this:

<link rel="stylesheet" href="http://mywebsite.com/css/default.css" type="text/css" title="default" />
<link rel="alternate stylesheet" href="http://mywebsite.com/csss/option1.css" type="text/css" title="option1" />
<link rel="alternate stylesheet" href="http://mywebsite.com/css/option2.css" type="text/css" title="option2" />
As you can see, the one you want to load as default is the "stylesheet" while the optional choices are "alternate stylesheet".

Next you add the javascript that will control the behaviour of the switching device and store a cookie. This javascript must appear after the link tags.

<script language="JavaScript" type="text/javascript" src="http://mywebsite.com/js/switcher.js"></script>
You can download that javascript from here - right click (or alt click) and save it.

And lastly, place some code to allow your user to make their choice - you can put this on a single page if you'd prefer it to not be repeated on every page. The link tags and javascript must be present on all pages that you want to use the styles, however.

<a href="#" onclick=setActiveStyleSheet('default'); return false; title="plain">plain</a> | <a href="#" onclick=setActiveStyleSheet('option1'); return false; title="corporate">coporate</a> | <a href="#" onclick=setActiveStyleSheet('option2'); return false; title="lovey">casual</a>
In the link tags, what is set as title is the value that these links use to choose the stylesheet. You can change default, option1 and option2 to anything you like, as long as you change it in both places. The title and name in the above links can be anything you like.

If you want to have another stylesheet that is used no matter what, then you set up up with rel="stylesheet" and OMIT the title from the link tag.

for example:
<link rel="stylesheet" href="http://mywebsite.com/css/persistant.css" type="text/css" />
That's called a persistant stylesheet.

And that's pretty much all there is to it! If you want to get more technical, why not meader over to a list apart, to where I got it from in the first place?
spacer
© 2002 - 2003 alison harrison. all rights reserved.
The authors of the content on this site asserts the right to ownership of copyright
All designs and images within this site are free for public use on ezboards only
Read our terms of use

Report site errors and copyright infringement to: ezdesign