SharePoint 2010 web part: D3 library error “Object doesn’t support this action” in Internet Explorer 10

If you are using the D3 javascript library developing web parts for SharePoint 2010 you can get the following error on Internet Explorer 10 (or 9):

Script445: object doesn't support this action

The error is due since SharePoint (sometimes) automatically adds the following meta tag inside the web page:

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

Thus the page is open in IE with compatibility mode for IE 8 and D3 doesn’t works.

Note that in IE 8 and lower versions D3 doesn’t works since such browsers doesn’t support the svg element. But from IE 9 the D3 library should works.

The error can be solved replacing such meta tag and setting other compatibility versions.

In the Page_Load method of your web part add the following code:

using System.Web.UI.HtmlControls;

// ...

protected void Page_Load(object sender, EventArgs e)
  foreach (Control c in Page.Header.Controls)
    if (c.GetType() == typeof(HtmlMeta))
        HtmlMeta meta = (HtmlMeta)c;
        if (meta.HttpEquiv == "X-UA-Compatible"
            && meta.Content == "IE=8")
            meta.Content = "IE=8; IE=9; IE=10; IE=11";
  // ...

Now in the web page containing your web part you should see the new meta tag:

<meta http-equiv="X-UA-Compatible" content="IE=8; IE=9; IE=10; IE=11" />

and D3 should work also on IE 10 (if not, try to close and reopen the browser).



Category BootstrapCategory CoffeescriptCategory DrupalCategory GravCategory HTMLCategory JavascriptCategory JoomlaCategory jQueryCategory LaravelCategory MagentoCategory PHPCategory SharePointCategory SpringCategory ThymeleafCategory WordPressCategory Workflow


Developed and designed by Netgloo
© 2016 Netgloo