11 replies [Last post]
fatfreddy
fatfreddy's picture
Offline
Enthusiast
Deep down under
Last seen: 15 years 19 weeks ago
Deep down under
Timezone: GMT+8
Joined: 2005-03-25
Posts: 390
Points: 0

I want to add a style sheet switcher to my website, basically, a high contrast version to aid it's accessibility.

My server gives me access to PHP but not MySQL
Is there any way of doing it without using Javascript (or at least using an accessible, degradeable javascript)?

Freddy

The only reason for time is so that everything doesn't happen at once
--Albert Einstein

Accessible webdesign Australia - webechodesigns

Tags:
Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 7 years 46 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

Accessible Style Sheet Swithcer

It should really be a case of just supplying a rel="alternate" stylesheet as browsers are meant to provide the accessibility requirements on this and many other issues and indeed good modern browsers do follow the guidelines and provide style sheet switching/selection; but of course we have to pander to that browser that consistently throws a deliberate spanner in the works at every flipping opportunity(sorry rant over, had a bad day with XP)

You naturally want to provide the proscribed route to a alternate stylesheet, but to provide a method of switching using PHP is relatively easy and doesn't require MySQL I managed a simple script using sessions and cookies but you can do it with just cookies to retain state from page to page, best thing is to follow a guide , this one is straightforward enough:

http://www.alistapart.com/articles/phpswitch/

Hugo.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

HellsBells
HellsBells's picture
Offline
Leader
Bedford, UK
Last seen: 14 years 30 weeks ago
Bedford, UK
Joined: 2004-04-07
Posts: 851
Points: 0

Accessible Style Sheet Swithcer

Hi Freddy

I'm in the process of rebuilding my site and I just added a couple of alternate stylesheets using this script: http://www.gr0w.com/articles/code/css_stylesheet_switcher_using_php_javascript_free/

Really easy to implement - much much easier than the current JS only "original" switcher that's on my current site.

Much much much much much easier.

My strategy is so simple an idiot could have devised it!

"Also, your CSS (no offence) makes me want to gouge my eyes out with a rusty spoon" - TPH

fatfreddy
fatfreddy's picture
Offline
Enthusiast
Deep down under
Last seen: 15 years 19 weeks ago
Deep down under
Timezone: GMT+8
Joined: 2005-03-25
Posts: 390
Points: 0

Accessible Style Sheet Swithcer

Excellent
Thanks both of you.

I'lllet you know how i get on

Cheers

Freddy

The only reason for time is so that everything doesn't happen at once
--Albert Einstein

Accessible webdesign Australia - webechodesigns

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 7 years 46 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

Accessible Style Sheet Swithcer

HB wrote:
Much much much much much easier


If not possibly a little over thought :? it's interesting but the array seems to over complicate matters, it's much the same idea as the ALA script, which is simplicity itself.

Slightly worried by comments such as:

"Of course this is fine as long as your visitor has Javascript enabled in their browser so that the cookie can be set and retrieved,"

and:

"(called STYLE) has been set (or by using PHP SESSION variables if Javascript is disabled)"

Why are talking about javascript here ? :? php is setting the cookie and reading a cookie is not a function controlled by javascript it doesn't matter whether javascript is enabled or disabled,does it ?
and I'm confused by a lack of a 'session_start()' at the start of a page requiring to read a session variable rather than the cookie.

I would tend to slightly wary of that script but I may well be wrong, and if it tests out ok great.

Hugo.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

HellsBells
HellsBells's picture
Offline
Leader
Bedford, UK
Last seen: 14 years 30 weeks ago
Bedford, UK
Joined: 2004-04-07
Posts: 851
Points: 0

Accessible Style Sheet Swithcer

I think I interpreted that bit about JS as that it's all very well using cookies if your user has JS enabled but what happens if they don't?

My strategy is so simple an idiot could have devised it!

"Also, your CSS (no offence) makes me want to gouge my eyes out with a rusty spoon" - TPH

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 7 years 46 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

Accessible Style Sheet Swithcer

It's still a mis-informed statement HB cookies are not a function of javascript; javascript or php can set or read cookies this is a php script javascript on or off has no bearing on the matter, it's I think the second statement that confuses me why do we care if javascript is off or on, php is doing the work, turning javascript off doesn't stop php processing cookie information, but maybe I'm just being overly pedantic; still the lack of session_start() worries me if cookies are off how does the session carry from page to page, have you tested this?

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

HellsBells
HellsBells's picture
Offline
Leader
Bedford, UK
Last seen: 14 years 30 weeks ago
Bedford, UK
Joined: 2004-04-07
Posts: 851
Points: 0

Accessible Style Sheet Swithcer

Yes - I'm still in the early stages but I've been back and forwards between pages (only got two done yet!) and closed and re-opened the site and it "remembers" the correct style set.

My strategy is so simple an idiot could have devised it!

"Also, your CSS (no offence) makes me want to gouge my eyes out with a rusty spoon" - TPH

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 7 years 46 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

Accessible Style Sheet Swithcer

As it should do as cookies are not set to expire anytime soon Smile my problem is with the fact that these are not session cookies and yet he is talking about carrying sessions around if cookies are disabled so was wondering what happens when you disable cookies and navigate to another page after changing stylesheets? (maybe I haven't read the script correctly)

Hugo.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

HellsBells
HellsBells's picture
Offline
Leader
Bedford, UK
Last seen: 14 years 30 weeks ago
Bedford, UK
Joined: 2004-04-07
Posts: 851
Points: 0

Accessible Style Sheet Swithcer

If I turn cookies off then the site reverts to default stylesheet on refresh and on changing pages.

My strategy is so simple an idiot could have devised it!

"Also, your CSS (no offence) makes me want to gouge my eyes out with a rusty spoon" - TPH

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 7 years 46 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

Accessible Style Sheet Swithcer

Then i'm right the talk of sessions is spurious and my instincts about the script seem founded, it's over complex,overworked the ALA version does the same thing along much simpler lines, although having said that it isn't rocket science to actually enable php sessions and session cookies rather than just set a plain cookie and then you could persist state across pages if cookies disabled, at least for the time the browser was opened sessions being lost on closing.

Hugo.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

Tyssen
Tyssen's picture
Offline
Moderator
Brisbane
Last seen: 8 years 7 weeks ago
Brisbane
Timezone: GMT+10
Joined: 2004-05-01
Posts: 8201
Points: 1386

Accessible Style Sheet Swithcer

While we're talking about this, the ALA method has been updated: http://www.stuffandnonsense.co.uk/resources/iotbs.html

How to get help
Post a link. If you can't post a link, jsFiddle it.
My blog | My older articles | CSS Reference