2012-01-15 138 views
1

我一直在为iframe的Chrome扩展搞乱,我似乎遇到了很多与iframe相关的问题。无论如何,我有一个iframe注入到一个网站(跨域)。我想要的是iframes背景图像继承父母页面背景(所以它融入)。所以这就是我想:chrome javascript dom删除iframe backgroundimage

//Setup iframe attributes 
iframe.setAttribute("id","injected_frame"); 
iframe.setAttribute("src", 'google.com'); 
iframe.setAttribute("width","100%"); 
iframe.setAttribute("height","425"); 
iframe.setAttribute("frameborder","0"); 
iframe.setAttribute("scrolling","auto"); 
iframe.setAttribute("style","backgroundImage: inherit"); <-- undefined error 

基本上它只是不工作,背景保持不变,并试图这样,当我得到一个未定义的错误。

+0

哦,我也试着object.body.style更换的最后一行,得到的未定义的错误也是如此。 – 2012-01-15 04:01:16

回答

1

您可能只是将"backgroundImage: inherit"更改为"background-image: inherit",但iframe上的任何其他内联样式可能会丢失,因为我相信这会完全重置样式属性。

因此,我反而建议用iframe.style.backgroundImage = "inherit";

+0

这两种方式都会导致undefined>。> – 2012-01-15 16:09:12

+0

等待一分钟,所以您试图在嵌入到iframe中时更改google.com的背景?如果是这样的话,由于跨域限制,我不相信JS有可能。阅读此:http://stackoverflow.com/questions/217776/how-to-apply-css-to-iframe – 2012-01-15 18:31:24

+0

那么谷歌部分只是一个例子,但是,这基本上是我想要完成的。我已经GOOGLE了很多,并且由于跨域限制,我得到了相同的回应。这是我试图做的谷歌扩展,不应该在manifest.json文件中的权限行使这成为可能(沙发我没有运气)?我会尝试使用内容脚本来强制一些css进入iframe的src url。希望这会工作。 – 2012-01-15 19:38:09