Permalink
Browse files

Fix for IE "Unknown runtime error"

Bug exists in both original NYTimes Emphasis and robflaherty's jQuery-ized Emphasis code.
  • Loading branch information...
1 parent 7999d05 commit dcb5fcac28b74420dab23510ae32e0b78ad8afc3 @lirenzhu lirenzhu committed May 5, 2011
Showing with 10 additions and 1 deletion.
  1. +10 −1 js/emphasis-src.js
View
11 js/emphasis-src.js
@@ -71,7 +71,16 @@ var Emphasis = {
addCSS: function() {
/* Inject the minimum styles rules required */
var st = document.createElement('style');
- st.innerHTML = 'p.' + this.classActive + ' span { background-color:#f2f4f5; } p span.' + this.classHighlight + ' { background-color:#fff0b3; } span.' + this.classInfo + ' { position:absolute; margin:-1px 0px 0px -8px; padding:0; font-size:10px; background-color: transparent !important} span.' + this.classInfo + ' a { text-decoration: none; } a.' + this.classActiveAnchor + ' { color: #000; font-size: 11px; }';
+ st.setAttribute('type', 'text/css');
+ /* for validation goodness */
+ var stStr = 'p.' + this.classActive + ' span { background-color:#f2f4f5; } p span.' + this.classHighlight + ' { background-color:#fff0b3; } span.' + this.classInfo + ' { position:absolute; margin:-1px 0px 0px -8px; padding:0; font-size:10px; background-color: transparent !important} span.' + this.classInfo + ' a { text-decoration: none; } a.' + this.classActiveAnchor + ' { color: #000; font-size: 11px; }';
+ try {
+ /* try the sensible way */
+ st.innerHTML = stStr;
+ } catch(e) {
+ /* IE's way */
+ st.styleSheet.cssText = stStr;
+ }
document.getElementsByTagName("head")[0].appendChild(st);
},

0 comments on commit dcb5fca

Please sign in to comment.