【问题标题】:IE11 User Agent String breaks <iframe>IE11 用户代理字符串中断 <iframe>
【发布时间】:2014-04-25 15:59:55
【问题描述】:

我正在使用一个 Wordpress 网站,该网站使用 iframe 对页面上填充的按钮进行外部调用,并提供指向同一外部网站的链接以进行预约。

iframe 在除 IE11 之外的所有浏览器中都能完美运行。 IE11 中的用户代理字符串设置为default,但如果我将 IE 的开发者工具中的字符串切换到任何 IE10 及以下版本,按钮就会呈现并完美运行。

那么,有谁知道如何将用户代理字符串设置为“默认”以外的任何内容? 注意:这与我已经完成的设置 ​​User-Agent 不同,它不起作用。 (或者是吗?......以及如何?)

我尝试过的示例:

&lt;meta http-equiv="X-UA-Compatible" content="IE=10"/&gt; 及其变体。

更新:作为一个额外的转折,&lt;iframe&gt; 加载不同的 doctypehtml 声明。这可能是我的问题的一部分吗? (我无权访问iframe 加载的代码)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

【问题讨论】:

  • 停止使用X-UAs,使用正确的 HTML5 文档类型。
  • 请仔细阅读Compatibility changes in IE11。结论是,将IE11降级到IE10是没有用的。 IE10 标准中的一些旧功能已从 IE11 中完全删除,降级不会将它们带回来。唯一的方法是以在 IE11 中也适用的方式编写 HTML、CSS 和脚本。这应该很容易,因为 IE11 中没有太多非标准的东西。
  • 如果您报告问题,您不会丢失任何东西。来自链接的 MSDN 文档:“Starting with IE11, document modes are deprecated and should no longer be used...”。
  • 我猜你的 iframe 源是浏览器嗅探。如果您可以将源更改为不是浏览器嗅探而是功能检测,您会更好。
  • 破坏 iframe 的不是 UA 字符串,而是 iframe 中的逻辑,因为它依赖于 UA 嗅探而不是特征检测。最好的办法是联系您在 iframe 中显示的内容的提供商,并要求他们更新代码以正确处理 IE11。

标签: wordpress internet-explorer iframe internet-explorer-11


【解决方案1】:

请更改您对 IE 的检测,不要依赖 UA 字符串,而是使用条件 cmets 和 document.documentMode

var tmp = document.documentMode, e, isIE;

// Try to force this property to be a string. 
try{document.documentMode = "";}
catch(e){ };

// If document.documentMode is a number, then it is a read-only property, and so 
// we have IE 8+.
// Otherwise, if conditional compilation works, then we have IE < 11.
// Otherwise, we have a non-IE browser. 
isIE = typeof document.documentMode == "number" || eval("/*@cc_on!@*/!1");

// Switch back the value to be unobtrusive for non-IE browsers. 
try{document.documentMode = tmp;}
catch(e){ };

http://www.pinlady.net/PluginDetect/IE/


如果您的代码使用此属性进行检测,还要检查 https://developer.mozilla.org/en-US/docs/Web/API/NavigatorID.userAgent


简而言之,破坏 iframe 的不是 UA 字符串,而是 iframe 中的逻辑,因为它依赖于 UA 嗅探而不是特征检测。

如果您无法控制 iframe 中显示的内容,最好联系您在 iframe 中显示的内容的提供商,并要求他们更新代码以正确处理 IE11。

【讨论】:

猜你喜欢
  • 2015-07-01
  • 2014-03-29
  • 2011-07-05
  • 2015-03-06
  • 1970-01-01
  • 2010-10-29
  • 2016-11-25
  • 2013-05-14
相关资源
最近更新 更多