[英]Adding attribute to iframe's body works in Chrome but not Firefox
Does anyone know why this works - that is to say, the attribute is added - in Chrome, but not in Firefox?有谁知道这为什么有效 - 也就是说,添加了该属性 - 在 Chrome 中,而不是在 Firefox 中?
this.wrapper.appendChild(this.ifr = document.createElement('iframe'));
this.ifr_doc = this.ifr.contentDocument || this.ifr.document;
this.ifr_doc.documentElement.querySelector('body').setAttribute('foo', 'bar'); //GRR...
No error;没有错误; it's just in Chrome, in the inspector, the attribute shows up, while in Firefox (v 41.0.2) it doesn't.它只是在 Chrome 中,在检查器中,该属性显示出来,而在 Firefox (v 41.0.2) 中则没有。
( this.wrapper
is a container housing the iframe) ( this.wrapper
是一个容纳 iframe 的容器)
try this:尝试这个:
if (this.ifr_doc.readyState == 'complete') {
this.ifr_doc.body.setAttribute('foo', 'bar');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.