IE10 d3.v3.js error: Unable to get property 'prototype' of undefined or null reference

vajrakumar picture vajrakumar · Mar 4, 2013 · Viewed 41.2k times · Source

My page is loading perfectly in IE9, Safari, Chrome & Firefox.

But when it coems to IE10 , it throws error : Unable to get property 'prototype' of undefined or null reference in d3.v3.js at line : d3_window.CSSStyleDeclaration.prototype.

 try {
    d3_document.createElement("div").style.setProperty("opacity", 0, "");
  } catch (error) {
    var d3_style_prototype = d3_window.CSSStyleDeclaration.prototype, d3_style_setProperty = d3_style_prototype.setProperty;
    d3_style_prototype.setProperty = function(name, value, priority) {
      d3_style_setProperty.call(this, name, value + "", priority);
    };
  }

I am not getting what exactly is being done here.

In try block even though setProperty method we can see in debugger on d3_document.createElement("div").style it is throwing error as : Object doesn't support property or method 'setProperty'

In catch block it tries to access prototype of window's CSSStyleDeclaration , but that is undefined.

Anybody occured with same problem while using d3.v3.js

Answer

Langdon picture Langdon · Aug 9, 2013

This can be fixed with a DOCTYPE:

<!DOCTYPE html>

And a meta tag:

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

Without those, IE will go into quirks mode and not understand what CSSStyleDeclaration is.