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).
References
- http://www.proactivespeaks.com/2013/09/12/fixing-sharepoint-compatibility-issues-with-internet-explorer-ie-9-and-ie-10/
- https://social.msdn.microsoft.com/Forums/ie/en-US/a5a38e2f-d950-4bdd-bb76-05fe6482efac/change-meta-xuacompatible-tag-at-runtime?forum=iewebdevelopment
- http://stackoverflow.com/questions/14611264/x-ua-compatible-content-ie-9-ie-8-ie-7-ie-edge