7

Używam respond.js (+1 dla tej biblioteki), a ja dostaję i błędów z następującą funkcją obiektu:IE8 respond.js „nieokreślone” jest null lub nie jest obiektem

translate = function (styles, href, media) { 
    // here I got 'undefined' error in IE 8 
    var qs = styles.match(/@media[^\{]+\{([^\{\}]*\{[^\}\{]*\})+/gi), 
     ql = qs && qs.length || 0; 

    //try to get CSS path 
    href = href.substring(0, href.lastIndexOf("/")); 

    var repUrls = function (css) { 
     return css.replace(/(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g, "$1" + href + "$2$3"); 
    }, 
    useMedia = !ql && media; 

    //if path exists, tack on trailing slash 
    if (href.length) { 
     href += "/"; 
    } 

    //if no internal queries exist, but media attr does, use that 
    //note: this currently lacks support for situations where a media attr is specified on a link AND 
    //its associated stylesheet has internal CSS media queries. 
    //In those cases, the media attribute will currently be ignored. 
    if (useMedia) { 
     ql = 1; 
    } 

    for (var i = 0; i < ql; i++) { 
     var fullq, thisq, eachq, eql; 

     //media attr 
     if (useMedia) { 
      fullq = media; 
      rules.push(repUrls(styles)); 
     } 
     //parse for styles 
     else { 
      fullq = qs[i].match(/@media *([^\{]+)\{([\S\s]+?)$/) && RegExp.$1; 
      rules.push(RegExp.$2 && repUrls(RegExp.$2)); 
     } 

     eachq = fullq.split(","); 
     eql = eachq.length; 

     for (var j = 0; j < eql; j++) { 
      thisq = eachq[j]; 
      mediastyles.push({ 
       media: thisq.split("(")[0].match(/(only\s+)?([a-zA-Z]+)\s?/) && RegExp.$2 || "all", 
       rules: rules.length - 1, 
       hasquery: thisq.indexOf("(") > -1, 
       minw: thisq.match(/\(\s*min\-width\s*:\s*(\s*[0-9\.]+)(px|em)\s*\)/) && parseFloat(RegExp.$1) + (RegExp.$2 || ""), 
       maxw: thisq.match(/\(\s*max\-width\s*:\s*(\s*[0-9\.]+)(px|em)\s*\)/) && parseFloat(RegExp.$1) + (RegExp.$2 || "") 
      }); 
     } 
    } 

    applyMedia(); 
}, 

Czy są jakieś inne obejścia? Próbowałem różnych ...

+0

Nie powinieneś potrzebować obejść. Czy ładujesz plik respons.js po załadowaniu całego CSS? Czy Twój CSS używa tylko zapytań o media o minimalnej/maksymalnej szerokości? Czy Twój CSS jest hostowany na tym samym serwerze co HTML i answer.js? – Blazemonger

+1

Na pierwszy rzut oka widzę w kodzie ".indexOf()", który nie jest obsługiwany w IE8. Czy możesz go usunąć i sprawdzić, czy nadal pojawia się błąd? – MacK

Odpowiedz

11

Miałem podobny problem w linii 121 (Respond.js 1.3.0). Przyczyną problemu był pusty arkusz stylów, a usunięcie go rozwiązało problem.

Brak wystarczających informacji, aby stwierdzić, czy twoja sprawa jest dokładnie taka sama, ale możesz spróbować sprawdzić, czy to pomaga.

+1

Świetna odpowiedź, ponieważ to było dokładnie to, czego potrzebowałem. Dzięki! – SeanPrice

Powiązane problemy