简体   繁体   English

javascript create iframe-自动创建头部和身体标签

[英]javascript create iframe - automatically creates head and body tags

It appears that 看起来

document.createElement('iframe');

automatically creates head and body tags. 自动创建headbody标签。

I've tested this in Firefox,Chrome and IE9+. 我已经在Firefox,Chrome和IE9 +中对此进行了测试。

Is this the standard or other browsers might not react like this. 这是标准还是其他浏览器可能不会做出这样的反应? I'm asking this because I wanna know if I need to check if those tags are created before inserting some elements in them. 我问这个问题是因为我想知道是否需要在插入一些元素之前检查是否创建了这些标签。 If I can avoid the check condition I'll be more than happy because I want to keep my js code as light as I can. 如果我可以避免检查条件,那我会很高兴的,因为我想让我的js代码尽可能的轻。

As far as I now, it's not standard, but supported by all common browsers. 就我现在而言,它不是标准的,但所有常见浏览器都支持。 The standard only defines that there is a HTML tag, so 该标准仅定义了一个HTML标记,因此

document.documentElement

is supported. 支持。 You can check for: 您可以检查:

document.documentElement.children.length > 0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM