nytimes / Emphasis

Dynamic Deep-Linking and Highlighting

Home Page:open.nytimes.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

IE doesn't like st.innerHTML

lirenzhu opened this issue · comments

IE doesn't running addCSS() starting at line 67 in emphasis-src.js, and the reason is st.innerHTML. If you try opening any article on NYTimes (and any subsequent websites that have implemented this version of Emphasis) in IE, you will see an "Unknown runtime error."

I've recently added a jQuery fork of Emphasis onto my own site and ran into the same problem. Here's the fix I employed:

addCSS: function() {
/*  Inject the minimum styles rules required */
    var st = document.createElement('style');
    // for xhtml validation goodness
    st.setAttribute('type', 'text/css');

    // placed all the css in a variable
    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 it the current way, if it fails (and it will in IE) do it the way that works in IE.
    try {
      st.innerHTML = stStr;
    } catch(e) {
      st.styleSheet.cssText = stStr;
    }

    document.getElementsByTagName("head")[0].appendChild(st);
},

If you want to do a Pull request with this change I'll test and include it

I believe this was fixed and merged earlier downstream. See dcb5fca.

Unless it pops up again I'm closing for now