语境:
我正在一个大型站点上工作,其中一些旧控件会在较新的浏览器中中断,因此我们不得不使用您的标准 meta X-UA-Compatible 标签强制 IE7 文档模式。我们已经更换了大部分问题控件,但没有时间和预算来全部更换。我们希望没有控件的页面可以在 IE 浏览器的当前文档模式下呈现,以利用其提供的客户端性能提升。问题是我无法让较新的 ie 浏览器像我想要的那样切换模式。网站的导航使用 iframe,我觉得这可能是我的主要问题。我在带有 iframe 的父页面上有我的 javascript。
我希望能够使用 javascript 来做到这一点,并且一直在尝试这样做。这就是我正在做的事情。它成功地更改了标签,但浏览器似乎并不关心。为了让浏览器考虑标签,我需要更改什么?
//tag swapping code
function FixIEMetaTag(url) {
//Remove current IE meta Tag
var iefixTagOld = document.getElementsByTagName('meta')[0];
if (iefixTagOld) { iefixTagOld.parentNode.removeChild(iefixTagOld); }
//Determine Document Type for IE browsers
var contentVal = 'IE=Edge';
if (IsPageWithBadGrid(url)) { contentVal = 'IE=7'; }
//Create and add new IE meta Tag
var iefixTag = document.createElement('meta');
iefixTag.setAttribute("http-equiv", "X-UA-Compatible");
iefixTag.setAttribute("content", contentVal);
var theHead = document.getElementsByTagName('head')[0];
theHead.insertBefore(iefixTag, theHead.firstChild);
}
//navigation code
function GoToPage(url) {
if (window.frames["ifrm"]) {
FixIEMetaTag(url);
window.open(url,"ifrm");
return false;
}
return true;
}