Discuss: Invasion of the Body Switchers
by Andy Clarke, James Edwards
- Editorial Comments
12 Safari & IE Problems
Nice work, really nice work.
I’ve looked through the JavaScript and it looks good. However, there’s a memory leak in IE/Win.
The problem is that inside the bodySwitcher constructor method an event handler is created. As it is created in the scope of the constructor, all fields of the object are in it’s scope. The handler is attached to the select node. This means the select node refers to the handler, refers to the object, which refers back to the select node. This circular reference cannot be cleaned by IE/Win.
The problem can be solved by not keeping references to DOM nodes on the object and retrieving needed nodes using a getElementById call.
See also http://jibbering.com/faq/faq_notes/closures.html#clMem
As for the Safari problems, when working on sIFR I found that Safari sometimes needed to be forced to repaint. You can read more at http://neo.dzygn.com/archive/2004/09/forcing-safari-to-repaint You’ll have to make sure though that you won’t be using innerHTML when the script is used in a XML page.
As for the script not functioning in IE/Mac, I found two possible reasons for this. One is that the onload event handlers don’t work in IE/Mac. The other is the space before the class name which seems to throw IE/Mac off.
posted at 11:43 am on November 19, 2004 by Mark Wubben
13 Nice Article
I cannot top the post above me, I thank you for making this idea more out in the public.
posted at 01:40 pm on November 19, 2004 by Nathan
14 Simple Things
It’s always brilliantly simple things like this that make me wonder, “Now why didn’t I think of that?”
I’ve had some problems with the other style switcher, so I’m hoping that this might work better.
posted at 01:59 pm on November 19, 2004 by Miles
15 Usage
There’s an obvious accessibility use, but other than that, is there really any reason to allow the user to switch stylesheets on the fly like this. I mean, as long as we are compliant, shouldn’t the accessibility issues resolve themselves for the most part?
posted at 02:39 pm on November 19, 2004 by Jason Gill
16 Finally :)
Great to see ALA back. I was raiding the archives whilst there was nothing new being published and I found some good stuff for PHP. But a new article is even better.
Just one thing about the code: instead of the more verbose
if (typeof window.addEventListener != “undefined”)
I’d opt for just
if(!window.addEventListener)
I thought ALA published on Tuesdays instead of Fridays. I much prefer Friday over Tuesday, because who doesn’t like Friday?
posted at 04:58 pm on November 19, 2004 by Dante
17 Gurney Halleck says: Interesting technique...
My! Am I glad I couldn’t sleep tonite! (it’s 2:45 AM here in Paris).
Yay! ALA is back!
Yeah, I got nothing to say…
posted at 06:45 pm on November 19, 2004 by ghola
18 Switcher
I liked how it works. I’m sure the concept can be extended to use it for another purposes.
posted at 07:55 pm on November 19, 2004 by Edgard Durand
19 Good Work!
Has possibilities as an accessibility feature or profile-site gimmick, but the biggest one for me is providing print-stylesheet hide/show options.
For example, on a blog, you can have a print-stylesheet so that a user can print the article, but with this, you can have a simple checkbox at the bottom for whether they’d like to print the comments also, or just the original text. You could also provide a box for surpressing images.
posted at 09:25 pm on November 19, 2004 by Mike Purvis
20 Accessibility
>Those that do, do not apply any persistence to a selected alternate stylesheet.
Firefox can do it via the extension Stylesheet Chooser (or the “Plus” variation of the extension).
And what about the Future ? I hope it will soon be implemented in browsers.
The very big problem is that now it is absolutely not possible to switch style without JavaScript. Not a good solution for accessibility :(
posted at 01:14 am on November 20, 2004 by Robin
Discussion Closed
New comments are not being accepted, but you are welcome to explore what people said before we closed the door.
Got something to say?
Discuss this article. We reserve the right to delete flames, trolls, and wood nymphs.
Create a new account or sign in below if you’d like to leave a comment.
Subscribe to this article's comments: RSS (what’s this?)






11 Firefox Fine
RE: Firefox…
No problem with Firefox, those are
media=print andmedia=projection styles. Unless you change the choice in the drop down and then print the page, you won’t see the difference.Welcome back ALA, it’s been a long time :)
posted at 11:33 am on November 19, 2004 by Justin Perkins