IHTMLDocument2::createStyleSheet method (Internet Explorer)

Switch View :
ScriptFree
IHTMLDocument2::createStyleSheet method

[This documentation is preliminary and is subject to change.]

Creates a style sheet for the document.

Syntax

C++

IHTMLStyleSheet** createStyleSheet(
  [in, optional]  BSTR sURL,
  [in, optional]  Integer iIndex
);

Parameters

sURL [in, optional]

A String that specifies how to add the style sheet to the document. If a file name is specified for the URL, the style information is added as a link object. If the URL contains style information, it is added to the style object.

iIndex [in, optional]

A Integer that specifies the index that indicates where the new style sheet is inserted in the styleSheets collection. The default is to insert the new style sheet at the end of the collection.

Return value

C++

a styleSheet object.

JavaScript

a styleSheet object.

Remarks

You can create up to 31 styleSheet objects with the createStyleSheet method. After that, the method returns an "Invalid Argument" exception. To create additional objects, use createElement and append them to the HEAD of the document as follows:


var styleSheet = document.createElement('STYLE');
document.documentElement.firstChild.appendChild(styleSheet);

Examples

This example uses the createStyleSheet method to create a link to a style sheet.


document.createStyleSheet('styles.css');

 

 

Build date: 3/14/2012

Community Content

AaronAsAChimp
31 limit workaround.
You can get around the limit by using @import within a stylesheet. Each stylesheet is allowed to have 31 @import's. This up's the limit to 961, which seems more reasonable.

Findo Gask
31 is the magic number... Why!?
Can anyone explain why this arbitrary limit has been imposed!? I just can't get my head around some of the decisions folk make when developing software.. What's the problem with 32+ style sheets? Why limit a collection to 31 items? Why not 41 or 3 or 12? I don't get it!

I've just hit this limit trying to manage custom control style sheets in a web application. I don't want to bundle all of my styles into one file but would prefer to keep style sheets with the controls they're supposed to style. Of course, other sensible browsers don't have any issue so why on earth does IE9.0..?

Totally confuzzed, someone please help me understand this..!?!

I guess I'm really asking, is there a work around? If you have a page with multiple user controls and you want those control styles included dynamically on the page along with any page-specific style sheets (I'm also using DevExpress themes with relevant styles also inserted dynamically) - how do you achieve this while maintaining modular design and organisation of the aforementioned controls, where each control is responsible (via an abstract base class) for inserting style sheet references into the head tag of the page it's on..?

Please refer to my next post for an answer..



 


Findo Gask
31 has to be the magic number... Here's why..
Ok, I posted my previous comment a tad hastily.. I should have looked a bit harder. Here's an article that indicates the reason why 31 is the limit..

http://blogs.msdn.com/b/ieinternals/archive/2011/05/14/internet-explorer-stylesheet-rule-selector-import-sheet-limit-maximum.aspx

But to continue ranting, if I may, wouldn't it seem rather obvious that a total of 31 style sheets would be a serious limitation..? In my experience, for maintainability and other good reasons, css files are kept with the elements they're supposed to style.

In this way, you can identify and fix any display issues or swap in new styles quite easily, rather than having to wade through an enormous style sheet with gazillions of obscure class and element identity names - if anyone has ever had to work with older versions of SharePoint, you'll understand that trying to get a handle on some of the bundled style sheets is like having to understand badly spelled Sanskrit...

Anyway, IE10 seems to have increased this silly limit to something more sensible as the above blog post indicates...

PabloViquez
31 limit?
I guess that the way IE constructs the objects, if you do 32 objects you might hit the blue screen of death... fail

takpar
stupid IE
what a stupid limitation. just 31 <style>, hehe!

John Sudds [Microsoft]
Upper limit is 31

You can only create 31 stylesheet objects with this method. After that, it throws an "Invalid argument" exception.

The same limit applies even if you create a STYLE element and append it to the document, as follows:

var ss = document.createElement('STYLE');
document.documentElement.firstChild.appendChild(ss);