0

I have a line of code that doesn't work in IE8 and lower.

var mediaQueryId = getComputedStyle( document.body, ":after" ).getPropertyValue("content");
var mediaQueryId = mediaQueryId.replace( /"/g, '' ); // 'null' is null or not a object

I tried to use this fix in order to make it work but I get this error:

'null' is null or not a object

Here's my code:

if (!window.getComputedStyle) {
    window.getComputedStyle = function(el, pseudo) {
        this.el = el;
        this.getPropertyValue = function(prop) {
            var re = /(\-([a-z]){1})/g;
            if (prop == 'float') prop = 'styleFloat';
            if (re.test(prop)) {
                prop = prop.replace(re, function () {
                    return arguments[2].toUpperCase();
                });
            }
            return el.currentStyle[prop] ? el.currentStyle[prop] : null;
        }
        return this;
    }
}

The website is http://www.gablabelle.com/

4

2 回答 2

0
getComputedStyle = function(){
    return el.currentStyle[prop] ? el.currentStyle[prop] : null;
    //                           you are returning null ----^
}

...

getComputedStyle( ... ).getPropertyValue( ... )
null                   .getPropertyValue( ... )

空是空:)

于 2012-10-16T02:20:35.937 回答
0
var mediaQueryId = getComputedStyle( document.body, ":after" )
                      ?getComputedStyle( document.body, ":after" ).getPropertyValue("content")
                      :'';

或类似的东西:

var foundStyle = getComputedStyle( document.body, ":after" );
if (foundStyle) {
   var mediaQueryId = foundStyle.getPropertyValue("content") || '';
   mediaQueryId = mediaQueryId.replace( /"/g, '' ); // 'null' is null or not a object
}
于 2012-10-16T02:28:29.360 回答