我有一份当前正在返回的父文档CSS1Compat
from document.compatMode
.
当我使用 jQuery 添加一个空白 iframe 时,如下所示:
$("body").append("<iframe id='test-iframe'></iframe>");
并检查新 iframe 的 compatMode,如下所示:
$("#test-iframe")[0].contentWindow.document.compatMode
它等于BackCompat
这会导致稍后出现区分大小写的问题以及其他一些样式问题。我无法改变案件,也无法控制它。新的iframe不应该是相同的compatMode吗?有办法强制吗?
这是因为浏览器正在加载一个基本的 html 文档(注意没有 doctype 声明):
<html>
<head></head>
<body></body>
</html>
由于没有声明 doctype,Chrome 将使用 BackCompat 模式。
如果您希望将其更改为其他模式,请将 src url 设置为使用 doctype 声明的 html 页面,或者写入 iframe 并将 html 设置为带有 doctype 的 html 页面。
var myContent = '<!DOCTYPE html><html><head></head><body></body></html>';
$("body").append("<iframe id='test-iframe'></iframe>");
var frame = $("#test-iframe")[0];
frame.contentWindow.document.open('text/htmlreplace');
frame.contentWindow.document.write(myContent);
frame.contentWindow.document.close();
console.log( frame.contentWindow.document.compatMode );
JSFiddle http://jsfiddle.net/d8u63dq6/1/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)