Skip to content

Commit

Permalink
By appending the style element before inserting CSS rules, we can pre…
Browse files Browse the repository at this point in the history
…vent a crash in IE when the HTML element has a background image applied. Also, this fix allows attribute selectors to continue working in IE7 after Respond runs through. It may fix other IE instability issues, but so far, just these two: Fixes #83, Fixes #69
  • Loading branch information
scottjehl committed Jan 16, 2012
1 parent 52e8efd commit 8016973
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion respond.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions respond.src.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@
docElemProp = docElem[ name ],
currWidth = doc.compatMode === "CSS1Compat" && docElemProp || doc.body[ name ] || docElemProp,
styleBlocks = {},
dFrag = doc.createDocumentFragment(),
lastLink = links[ links.length-1 ],
now = (new Date()).getTime();

Expand Down Expand Up @@ -181,18 +180,20 @@
ss.type = "text/css";
ss.media = i;

//originally, ss was appended to a documentFragment and sheets were appended in bulk.
//this caused crashes in IE in a number of circumstances, such as when the HTML element had a bg image set
head.insertBefore( ss, lastLink.nextSibling );

if ( ss.styleSheet ){
ss.styleSheet.cssText = css;
}
else {
ss.appendChild( doc.createTextNode( css ) );
}
dFrag.appendChild( ss );

//push to appendedEls to track for later removal
appendedEls.push( ss );
}

//append to DOM at once
head.insertBefore( dFrag, lastLink.nextSibling );
},
//tweaked Ajax functions from Quirksmode
ajax = function( url, callback ) {
Expand Down

0 comments on commit 8016973

Please sign in to comment.