overwrite X-UA-Compatible meta in SharePoint 2010
Asked Answered
H

2

10

I am working on SharePoint 2010 and I want to use <meta http-equiv="X-UA-Compatible" content="IE=edge"/> for a specific page. The master page is setting it to "IE=8" which doesn't allow me to use box-shadow in CSS e.g.

I don't have access to the masterpage to change it. Also I have read that changing that meta in master page is not recommended as it might cause issues with other things like calendars or whatever.

So my Q is: is there any way of overwriting the X-UA-Compatible meta tag in a simple page (.aspx)?

Heptode answered 8/10, 2014 at 12:31 Comment(0)
M
8

Among the ways to change the compatibility mode for page two of them seems promising:

  • Via X-UA-compatible HTTP header: The web server has requested a legacy document mode via an HTTP header.
  • Via X-UA-compatible meta tag: The webpage developer used a meta tag to specify a legacy document mode.

SharePoint 2010's default master page hardcodes X-UA-Compatible meta tag, and meta tag takes precedence over HTTP header, so this can't be done on HTTP level. This leaves us with the second option.

It seems that the first X-UA-compatible meta tag encountered on the page is used by IE (although it's ambiguous in different articles and missing in MSDN documentation). If you write SharePoint UserControl or WebPart you might add this code e.g. in Page_Load() method to add this header as the first one:

 HtmlMeta metaEdgeIE = new HtmlMeta();
 metaEdgeIE.HttpEquiv = "X-UA-Compatible";
 metaEdgeIE.Content = "IE=EDGE";
 Page.Header.Controls.AddAt(0, metaEdgeIE);

where HtmlMeta comes from System.Web.UI.WebControls namespace.

By iterating through Page.Header.Controls you could probably also find and remove the meta tag added by default by SharePoint, although the code above seems enough to trigger Edge mode in IE11.

Mcculloch answered 22/12, 2014 at 15:50 Comment(1)
"missing documentation" it is documented here (maybe wasn't before): learn.microsoft.com/en-us/openspecs/ie_standards/ms-iedoco/…Mccue
H
0

If you can edit the master page and only want to change the compatibility for particular pages you can take a similar approach to buli (thanks) but overwrite the existing Content of the meta tag. For your meta tag in the master page, give it an id and runat server

<meta id="metaIE" runat="server" http-equiv="X-UA-Compatible" content="IE=edge">

In your page load, find the control from master, cast to HtmlMeta and change the Content

Dim metaIE = DirectCast(Master.FindControl("metaIE"), HtmlMeta)
metaIE.Content = "IE=10"
Haematic answered 8/10, 2015 at 15:4 Comment(1)
if you can edit the master page then there's no issue is there?Ney

© 2022 - 2024 — McMap. All rights reserved.