overwrite X-UA-Compatible meta in SharePoint 2010

纵饮孤独 提交于 2019-12-08 15:41:27

问题


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)?


回答1:


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.




回答2:


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"


来源:https://stackoverflow.com/questions/26256968/overwrite-x-ua-compatible-meta-in-sharepoint-2010

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!