gwatts / jquery.sparkline

A plugin for the jQuery javascript library to generate small sparkline charts directly in the browser
http://omnipotent.net/jquery.sparkline/
1.24k stars 278 forks source link

[IE7, IE8] addCSS() throws "Invalid Argument" exception after 30+ calls to document.createStyleSheet() #94

Closed AspNyc closed 11 years ago

AspNyc commented 11 years ago

Example: http://jsbin.com/iniGoxe/3

Kind of an obscure bug, but one that cropped up for us today when our new consulting company loaded one too many CSS files. Basically, there's a known limitation in IE7 and IE8 where if more than 30 spreadsheets are loaded, it throws an "Invalid Argument" exception:

  1. http://msdn.microsoft.com/en-us/library/ms531194%28VS.85%29.aspx
  2. http://dean.edwards.name/weblog/2010/02/bug85/
  3. http://stackoverflow.com/questions/3211991/does-ie-8-have-a-limit-on-number-of-stylesheets-per-page

Our workaround was to dynamically create a STYLE element and add it as a child of the HEAD element:

// http://paulirish.com/2008/bookmarklet-inject-new-css-rules/
addCSS = function(css) {
    var tag;
    //if ('\v' == 'v') /* ie only */ {
    if (document.createStyleSheet) {
        // Only workaround the cases that need it.
        if (document.styleSheets.length >= 30) {
            var styleNode = document.createElement('style');
            styleNode.type = "text/css";
            styleNode.styleSheet.cssText = css;
            document.getElementsByTagName('head')[0].appendChild(styleNode);
        }   
        else {
            document.createStyleSheet().cssText = css;
        }
    } else {
        tag = document.createElement('style');
        tag.type = 'text/css';
        document.getElementsByTagName('head')[0].appendChild(tag);
        tag[(typeof document.body.style.WebkitAppearance == 'string') /* webkit only */ ? 'innerText' : 'innerHTML'] = css;
    }
};

Does this make sense?

gwatts commented 11 years ago

Actually this is already fixed in the master branch as of July 30th: https://github.com/gwatts/jquery.sparkline/commit/843dfd5e44cb6cc5e4d2d1a913215f74bf045dbb

It hasn't made it to a release as yet though

AspNyc commented 11 years ago

You guys are awesome -- thanks for the fix as well as the reply!

On Thu, Sep 26, 2013 at 5:48 PM, Gareth Watts notifications@github.comwrote:

Actually this is already fixed in the master branch as of July 30th: 843dfd5https://github.com/gwatts/jquery.sparkline/commit/843dfd5e44cb6cc5e4d2d1a913215f74bf045dbb

It hasn't made it to a release as yet though

— Reply to this email directly or view it on GitHubhttps://github.com/gwatts/jquery.sparkline/issues/94#issuecomment-25206904 .