That JavaScript / PHP Styleswitcher

“So the line is duplicated in my head section in two places”

I finally got around to playing with that styleswitcher and putting in a PHP backup for all of the JavaScript deficient visitors. There were a few small snags that made me scratch my head for a moment or two but basically its just a hybrid of the A List Apart - Alternative Style: Working With Alternate Style Sheets and their Build A PHP Switcher articles. While its not rocket science it did have some moments of interest.

When I sent the querystring to set the cookie I wanted to have my JavaScript cake and eat it too so when I url encoded

?set=defstyles&#default

which looks a bit odd but basically its sending the value of defstyle for $set to the PHP script and appends the #default variable that the JavaScript requires. I actually didn’t realise I could do that at the time so that was of interest. Querystrings aren’t meant to have # characters in them but it worked with the # on the end of the string. Thus both variables are coming from the same link.

The other note of interest was where I put my link element for the stylesheets in the head section, used to retreive the PHP value, in relation to the other links and @imports used for my other CSS files which JavaScript utilises. For Firefox the link element needed to be above the @import and higher in the head section while for Internet Explorer to work the link element had to be below the @import statement. So the line is duplicated in my head section in two places which is kind of quirky.

Anyway wonders never cease and I finally got around to fixing the styleswitcher today so it now has an efficient PHP alternative to fall back on if anyone not JavaScript capable strolls through.

Unfortunately either way if they happen to have cookies disabled then its all a moot point I guess. But its an improvement. Thanks Edward for pulling me up on that one earlier in the week, I’d honestly forgotten to get it done. Cursory testing aside if you find any pages or platforms it doesn’t work on I’d be interested to hear.

Y’know I’m beginning to realise I AM a geek after all…

Comments are closed.


Sitemap