基于iframe网址,使用javascript更改X-UA-Compatible元标记 [英] changing X-UA-Compatible meta tag with javascript based on iframe url

查看:61
本文介绍了基于iframe网址,使用javascript更改X-UA-Compatible元标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上下文:

我正在一个大型站点上工作,其中一些旧的控件在较新的浏览器中可能会损坏,因此我们不得不使用您的标准meta X-UA-Compatible标签强制IE7文档模式.我们已替换了大多数问题控件,但没有时间和预算来全部替换它们.我们希望页面不具有在IE浏览器中以当前文档模式呈现的控件的页面,以利用提供的客户端性能提升.问题是我无法获得较新的浏览器来切换我想要的模式.该网站的导航使用的是iframe,我认为这可能是我的主要问题.我的iframe的父页面上有我的JavaScript.

I am working on a large site with some old controls that break in newer browsers so we have had to force IE7 document mode with your standard meta X-UA-Compatible tag. We have replaced most of the problem controls but do not have the time and budget to replace them all. We would like to have the pages that dont have the controls to render in the current document mode for IE browsers to take advantage of the client side performance boosts that that provides. The problem is that I am having trouble getting that the newer ie browsers to switch modes like i want. The navigation of the site uses an iframe which i feel is probably my main issue. I have my javascript on the parent page with the iframe.

我希望能够使用javascript做到这一点,并且一直在尝试这样做.这是我在做什么.它成功更改了Tag,但浏览器似乎并不在乎.我需要更改什么才能使浏览器考虑标记?

I would like to be able to do this with javascript, and have been attempting to do so. Here is what I am doing. It successfuly changes the Tag, but the browser doesnt seem to care. What do I need to change in order for the browsers to consider the Tags?

     //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;
     }

推荐答案

要生效,在加载页面时,必须存在 X-UA-Compatible 元标记.到Javascript运行时,为时已晚.

To be effective, the X-UA-Compatible meta tag must be present when the page is loaded. By the time that Javascript runs, it's too late to change.

如果您确实需要为iframe的内容打开和关闭IE7模式,最好的选择是保留两个带有不同 X-UA-Compatible 标签的网页版本,或者通过URL参数(例如,?mode = ie7 ?mode = edge )传递兼容性标记.

If you really need to switch IE7 mode on and off for the content of an iframe, your best bet is to keep two versions of the page with different X-UA-Compatible tags, or to pass the compatibility flag in via a URL parameter (e.g, ?mode=ie7 vs. ?mode=edge).

这篇关于基于iframe网址,使用javascript更改X-UA-Compatible元标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆