Javascript 将属性添加到iframe';s的主体在Chrome中工作,但在Firefox中不工作
有人知道为什么在Chrome中,而不是在Firefox中,这个属性是被添加的吗Javascript 将属性添加到iframe';s的主体在Chrome中工作,但在Firefox中不工作,javascript,iframe,document,Javascript,Iframe,Document,有人知道为什么在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')
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...
没有错误;它只是在Chrome浏览器中,在inspector中显示属性,而在Firefox(V41.0.2)中则没有
(this.wrapper
是一个容纳iframe的容器)尝试以下操作:
if (this.ifr_doc.readyState == 'complete') {
this.ifr_doc.body.setAttribute('foo', 'bar');
}
检查你的
这个.ifr\u doc.documentElement.querySelector('body')
元素,它是在ff中定义的吗?是的,我检查过了,很有趣-文档总是以未初始化的状态返回,即使我稍后通过超时再次检查。那我怎么初始化呢+1.从读取MDN开始,我不-不能-手动初始化它-只有在readystatechange或domcontentloaded事件触发时才会初始化它。因为我正在重新创建一个新的iframe和文档,所以我不确定我能在这里做什么。也许我应该把这作为一个单独的问题发表。