简体   繁体   English

向 iframe 的主体添加属性在 Chrome 中有效,但在 Firefox 中无效

[英]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.

相关问题 iFrame文字未在Firefox上显示,但在Chrome上适用(document.body.innerHTML) - iFrame Text Not showing up on Firefox but works on Chrome (document.body.innerHTML) iframe 主体上的 ResizeObserver 在 Chrome 和 Firefox 上的行为不同 - ResizeObserver on iframe body behaves differently on Chrome and Firefox iframe中的PDF-适用于Firefox,但不适用于OSX上的Chrome - PDF in iframe - works in Firefox, but not Chrome on OSX 解析XML标签属性在Firefox中有效,但在Chrome中不起作用 - Parsing XML tag attribute works in Firefox but not in Chrome 将HTML插入iframe在Firefox / Chrome / Opera中有效,但在IE7 / 8中则无效 - Inserting HTML to iframe works in Firefox/Chrome/Opera but not in IE7/8 Firefox iframe中的getElementById返回null,但可在Safari / Chrome中使用 - getElementById in Firefox iframe returns null but works in Safari/Chrome 从iFrame更改父页面URL在IE中工作,但在Firefox和Chrome中不起作用 - Change parent page url from an iFrame works in IE but not in Firefox and Chrome 在子框架中访问父框架中的父iframe元素只能在Firefox中运行,而不能在Chrome中运行 - Accessing parent iframe element in child frame works in Firefox and not in Chrome iframe 沙盒中的 WebSocket 在 Firefox 上失败,但适用于 Edge/Chrome - WebSocket within iframe sandbox fails on Firefox, but works on Edge/Chrome iframe.height(100); 在Chrome中添加,并在Firefox中设置 - iframe.height(100); is adding in chrome, and setting in firefox
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM