Switch Stylesheet

C

chlori

I would like to give the user/visitor the option to
chose one out of eight stylesheets. I can't use an
alternative stylesheet, because it doesn't work in IE
(does ist?) and as soon as the user clicks on a link,
then the default stylesheet is selected again...

How can I let the user chose a stylesheet and keep it
even when navigating through the site?

(files are .php)

Thanks
chlori
 
D

Deryck

chlori said:
I would like to give the user/visitor the option to
chose one out of eight stylesheets. I can't use an
alternative stylesheet, because it doesn't work in IE
(does ist?) and as soon as the user clicks on a link,
then the default stylesheet is selected again...

How can I let the user chose a stylesheet and keep it
even when navigating through the site?

(files are .php)

See if http://www.alistapart.com/articles/n4switch/ is a solution that you
can use. It uses Javascript and apparently works on IE. I havent tried it
though.

Deryck
 
T

Toby A Inkster

Deryck said:

.... albeit a stupid one. It creates a dependency on Javascript. If you're
one of those ~10% of people who disable Javascript, then you don't get any
stylesheets.

Apart from the stupid solution you have two other options:

2. Use a server-side script (w/ cookies) to choose styles.
3. Rely on the browser's handling of rel="alternate stylesheet"
(which I will refer to as RAS for brevity).

(and then you have combinations of the three options).

Straight off, I'll tell you that option 3 is almost as stupid as option 1.
Here's why:

- Internet Explorer (for any OS) does not support RAS.
- If you use AS, many browsers (including *IE/win*, Gecko, Opera,
Safari, Konq) will download *all* the AS when it loads the page
"just in case" the user wants to switch stylesheet. Yes, *all*
the linked alternate stylesheets. Konq and Safari even go so far
as to download any images pulled in by them!
- Konq is just weird anyway.
- The ability to mix and match AS is limited.

So I have come to the conclusion that option 2 is the only sane choice --
perhaps combining it with a little client-side scripting to make it work a
little smoother. Stay away from RAS at all costs -- it will make your
pages load slower and use up your bandwidth for no real reason.

References:
http://groups.google.com/[email protected]
http://bugs.kde.org/show_bug.cgi?id=54335
http://groups.google.com/[email protected]
(basic example, though add in cookies)
http://www.goddamn.co.uk/tobyink/TESTING/ (my new switcher)
 
C

chlori

Toby A Inkster schrieb am 27.06.2004 09:17:
http://groups.google.com/[email protected]
(basic example, though add in cookies)

Thanks, this looks like the thing I was looking for!

But: I have never used cookies on a site. I will need
them to "remember" which style was used. But how?

Can I not change pages and keep the style=whatever in
the url?

Something like this:
<a href="index.php?style=[1]">Standard</a>

[1] the used style

chlori
 
D

Dylan Parry

chlori said:
Can I not change pages and keep the style=whatever in the url?

Yes, you can do this too. In fact this is a better solution than using
cookies as one can disable cookies but not this method :)
 
W

Whitecrest

Thanks, this looks like the thing I was looking for!
But: I have never used cookies on a site. I will need
them to "remember" which style was used. But how?

A simple search in google for "create cookies" and your server side
scripting language will result in thousands of examples.
Can I not change pages and keep the style=whatever in
the url?

Yes you can pass that information all around with the url.
 
D

Deryck

Toby A Inkster said:
... albeit a stupid one. It creates a dependency on Javascript. If you're
one of those ~10% of people who disable Javascript, then you don't get any
stylesheets.
Apart from the stupid solution you have two other options:
2. Use a server-side script (w/ cookies) to choose styles.
3. Rely on the browser's handling of rel="alternate stylesheet"
(which I will refer to as RAS for brevity).
(and then you have combinations of the three options).
Straight off, I'll tell you that option 3 is almost as stupid as option 1.
Here's why:
- Internet Explorer (for any OS) does not support RAS.

<snipped>

Hence the sentence in my post.....

" It uses Javascript and apparently works on IE."

Which amittedly could have been rephrased to better emphasise that use of
Javascript was seen to be a disadvantage, but given that almost daily a
reference is made here to the 10-15% who dont use Javascript I felt it
superfluous.

Cheers

Deryck
 
C

chlori

Dylan Parry schrieb am 27.06.2004 13:09:
Yes, you can do this too. In fact this is a better solution than using
cookies as one can disable cookies but not this method :)

Ok, worked.

But now there's another question:
My link for changing the style looks like this:

<a href="index.php?style=standard">Standard</a>

I want to include those links on every page, so I can
just change one file and they all change...

So I have to change the "index.php" into "thisfile". Is
that possible?

<a href="[1]?style=standard">Standard</a>

[1] this file

chlori
 
T

Toby A Inkster

chlori said:
Can I not change pages and keep the style=whatever in
the url?

You can, but that's a pain in the arse to actually implement for any
number of pages greater than, say, 6. And it means that search engines,
and just regular people linking to your pages might link to particular
style sheets instead of the "default" one.
 
U

Uncle Pirate

Toby said:
... albeit a stupid one. It creates a dependency on Javascript. If you're
one of those ~10% of people who disable Javascript, then you don't get any
stylesheets.

Apart from the stupid solution you have two other options:

2. Use a server-side script (w/ cookies) to choose styles.

The same ~10% with js off probably don't do cookies either. I like
eating cookies; I don't like them in/on my computer. I guess there is
no good option unless you server side rewrite the page.

--
Stan McCann "Uncle Pirate"
Webmaster/Computer Center Manager, NMSU at Alamogordo
Cooordinator, Tularosa Basin Chapter, ABATE of NM AMA#758681
'94 1500 Vulcan (now wrecked) :( http://surecann.com/Dcp_2068c.jpg
A zest for living must include a willingness to die. - R.A. Heinlein
 
D

derek giroulle

chlori said:
I would like to give the user/visitor the option to chose one out of
eight stylesheets. I can't use an alternative stylesheet, because it
doesn't work in IE (does ist?) and as soon as the user clicks on a link,
then the default stylesheet is selected again...

How can I let the user chose a stylesheet and keep it even when
navigating through the site?

(files are .php)

Thanks
chlori

you can find an example at r7designer.com

http://www.r7designer.com/downloads/details.php?id=2

free template called aqua

should be a good example

derek
 
T

Tim Johansson

chlori said:
I would like to give the user/visitor the option to
chose one out of eight stylesheets. I can't use an
alternative stylesheet, because it doesn't work in IE
(does ist?) and as soon as the user clicks on a link,
then the default stylesheet is selected again...

How can I let the user chose a stylesheet and keep it
even when navigating through the site?

(files are .php)

Thanks
chlori

I'd use sessions to store the Stylesheet the user chooses, since you're
apparently able to use PHP.
 
J

Jeff Thies

How can I let the user chose a stylesheet and keep it
I see no real problem with the javascript approach. After all it is just an
optional stylesheet and no harm is done if you can't switch. I'd just switch
the href of the stylesheet though.

Tons of way to do this server side, and your pages are server driven.

The stylesheet doesn't have to have a .css extension, I think that you'll
want to set a text/css Content-type if it isn't. At one time I used to
store/edit these in database tables.

Jeff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top