IHTMLStyleSheet::addImport method (Internet Explorer)

Switch View :
ScriptFree
IHTMLStyleSheet::addImport method

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

Adds a style sheet to the imports collection for the specified style sheet.

Syntax

C++

Integer* addImport(
  [in]            BSTR sURL,
  [in, optional]  Integer iIndexRequest
);

Parameters

sURL [in]

String that specifies the location of the source file for the style sheet.

iIndexRequest [in, optional]

Integer that specifies the requested position for the style sheet in the collection. If this value is not given, the style sheet is added to the end of the collection.

Return value

C++

 a zero-based index value indicating the position of the imported style sheet in the imports collection.

JavaScript

 a zero-based index value indicating the position of the imported style sheet in the imports collection.

 

 

Build date: 3/14/2012

Community Content

chitetskoy
Pushing to the IE Limit
I had made up another test, this time having 10 imported stylesheets, each containing 4000 rules (short of 95 rule limit) in one stylesheet. I had made a css rule, which was not found in any of the imported stylesheets, following the line of imports in the same stylesheet. What had happened is that, the Internet Explorer browser (which was at ver. 6) do able to read that last rule.

Theoretically, the maximum total number of rules from all of the imported stylesheets in a single page combined would be about 3 MILLION!

4095 rules/imported stylesheet
x 31 imported stylesheet/stylesheet
x 31 stylesheet/html document

aside from the 125K rules from all non-imported stylesheets combined

4095 rules/stylesheet
x 31 stylesheets/page.

However, having a lots of imports in ten stylesheets each (assuming that you have ten stylesheets each having ten imports, each import having 4000+ rules) can degrade performance in browsers and may even cause some browsers (such as Mozilla) to crash. However, this is not much of concern, average web developers wouldn't bother pushing through this limit.


chitetskoy
Limit is 31 imports
Whether a CSS import is made in a CSS file itself (by using @import) or dynamically by JavaScript, the limit per stylesheet is 31. Beyond that number, all other imports in that stylesheet will be ignored. Additionally, when trying to add an import by JavaScript, the browser will return an "Invalid argument" error.

Try this yourself: add this JavaScript code before the end of a test HTML file.
for(var i=0; i<31; i++) { // 1 more than the limit
document.styleSheets[1].addImport("style_1.css");
}
document.styleSheets[1].addImport("style_2.css");
and make sure that the first stylesheet in your page still has no imports yet.

The style_1.css file must be empty.

In the style_2.css file, create the following text:
BODY {background: red !important;}

When the style_2.css file is successfully imported, the body background should turn red.