pace icon indicating copy to clipboard operation
pace copied to clipboard

querySelector error in IE11

Open tony-dunlop opened this issue 12 years ago • 3 comments

Hi,

Loading In IE 11 produces the following error: "Object doesn't support property or method 'querySelector'"

using version 0.4.17

on line 119 el = document.querySelector("[data-pace-" + key + "]");

i tried swapping the querySelector for a jQuery selector, (and then all the other ones in the script), as every querySelector doesnt seem to work properly, but didnt have any joy,

jserror

tony-dunlop avatar Mar 10 '14 12:03 tony-dunlop

Ah ok, solved it myself the page was being rendered in IE8 emulate, (which seems to user ie5 javascript lib) it was fixed by telling the page to render in IE10 as querySelector is not avaliable to less than ie8 so if the browser was in a legacy render mode it would break. I guess tellin it to use IE8 would do.

Also worth putting the script tags which call pace.js in conditional comments so it doesn't try to load in IE 5,6,7,8

another 3 hours of my life wasted battling with legacy IE....

tony-dunlop avatar Mar 10 '14 15:03 tony-dunlop

Can you help me? i am too. Object doesn't support property or method 'querySelector'

dophu17 avatar Oct 06 '15 07:10 dophu17

This is an issue with IE7 or lower (or IE8+ running in compatibility view mode where the page is forced into IE7 or lower)

The querySelector or querySelectorAll functions aren't available. A simple fix is to add them if they are undefined:


(function () {

    //Fix for IE7 and lower 
    if (!document.querySelectorAll) {
      document.querySelectorAll = function (selectors) {
        var style = document.createElement('style'), elements = [], element;
        document.documentElement.firstChild.appendChild(style);
        document._qsa = [];

        style.styleSheet.cssText = selectors + '{x-qsa:expression(document._qsa && document._qsa.push(this))}';
        window.scrollBy(0, 0);
        style.parentNode.removeChild(style);

        while (document._qsa.length) {
          element = document._qsa.shift();
          element.style.removeAttribute('x-qsa');
          elements.push(element);
        }
        document._qsa = null;
        return elements;
      };
    }

    //Fix for IE7 and lower 
    if (!document.querySelector) {
      document.querySelector = function (selectors) {
        var elements = document.querySelectorAll(selectors);
        return (elements.length) ? elements[0] : null;
      };
    }
    ...

EnricoSaunders avatar Jul 29 '16 04:07 EnricoSaunders