View Full Version : Style Sheet Switcher- 30 max Css's for IE?

05-25-2012, 04:46 PM
1) Script Title:

Style Sheet Switcher (v1.1)

2) Script URL (on DD):


3) Describe problem:

I am using styleswitch.js as a test bed to show various different background colors (35 different style sheets including the default) for a webpage. In IE, there seems to be a limit on how many various css's I can use. (stops working after the 30th .css).

In Firefox it works great for all of them.

So is there something I can add to allow my full list to work on IE?

Thanks for any help.

05-25-2012, 06:30 PM
I believe that's a limitation of IE. I discovered it when I was working on a script where I was appending stylesheets to the head with each change of a slide in a slideshow. It stopped working after about 30 slide changes. I ended up replacing instead of removing after the first insertion.

At the time I had thought it was a limitation on inserting things in the head. But I have since discovered, in another script I was working on that, for example an unlimited number of script tags can be inserted.

Something like that could be done with this script. It would be a bit of a rewrite though. Instead of switching sheets, their url's could be listed in an array or object. An object would be better I believe. Whichever sheet was to be active could be set as the href attribute of a single stylesheet link either already on the page, or that could be appended the first time it's needed, and/or that could be replaced by one with the desired href url for each change.

When I get more time - probably later today or over the weekend, I'll do it.

05-25-2012, 07:51 PM
ok, thanks.

We just need to get everyone to stop using IE, that would solve most issues.

05-26-2012, 06:36 AM
Good luck with that. OK, this rewrite works (probably without any limits, tested with 1000 alternate sheets):


BTW, I double checked that there really is a problem in IE visa vis the number of sheets. There is. It's not that you cannot have a lot of sheets, rather that IE stops recognizing them as valid link tags after awhile. Amounts to the same thing. It will still count them and parse them as tags, it just won't execute their rules on the page.

My solution was to remove them after cataloging their titles and hrefs in an object and their titles in an array.

As a result, you can use the same markup as the original script and you don't have to set up any array or object.

Any questions, let me know.

05-29-2012, 07:49 PM
New .js file works great! Thanks John!