简体   繁体   中英

javascript create iframe - automatically creates head and body tags

It appears that

document.createElement('iframe');

automatically creates head and body tags.

I've tested this in Firefox,Chrome and 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.

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

document.documentElement

is supported. You can check for:

document.documentElement.children.length > 0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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