Html 更改 iframe 问题的背景颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14830852/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change background color of iframe issue
提问by Paul T.
I need to change background color to white of the displayed page if <iframe></iframe>
. Is that possible? Now background of the original website is gray.
如果 ,我需要将显示页面的背景颜色更改为白色<iframe></iframe>
。那可能吗?现在原网站的背景是灰色的。
<iframe allowtransparency="true" style="background-color: Snow;" src="http://zingaya.com/widget/9d043c064dc241068881f045f9d8c151" frameborder="0" height="184" width="100%">
</iframe>
I want to change the background of loaded page
我想更改加载页面的背景
回答by Kingk
An <iframe>
background can be changed like this:
一个<iframe>
背景是可以改变这样的:
<iframe allowtransparency="true" style="background: #FFFFFF;"
src="http://zingaya.com/widget/9d043c064dc241068881f045f9d8c151"
frameborder="0" height="184" width="100%">
</iframe>
I don't think it's possible to change the background of the page that you have loadedin the iframe.
我认为无法更改您在 iframe 中加载的页面的背景。
回答by Angela
JavaScript is what you need. If you are loading iframe when loading the page, insert the test for iframe using the onload event. If iframe is inserted in realtime, then create a callback function on insertion and hook in whatever action you need to take :)
JavaScript 正是您所需要的。如果您在加载页面时加载 iframe,请使用 onload 事件插入 iframe 的测试。如果 iframe 是实时插入的,则在插入时创建一个回调函数,并在您需要采取的任何操作中挂钩:)
回答by J Cox
just building on what Chetabahana wrote, I found that adding a short delay to the JS function helped on a site I was working on. It meant that the function kicked in after the iframe loaded. You can play around with the delay.
只是建立在 Chetabahana 所写的基础上,我发现向 JS 函数添加一个短暂的延迟对我正在处理的网站有所帮助。这意味着该函数在 iframe 加载后启动。你可以玩弄延迟。
var delayInMilliseconds = 500; // half a second
setTimeout(function() {
var iframe = document.getElementsByTagName('iframe')[0];
iframe.style.background = 'white';
iframe.contentWindow.document.body.style.backgroundColor = 'white';
}, delayInMilliseconds);
I hope this helps!
我希望这有帮助!
回答by Chetabahana
You can do it using javascript
你可以用javascript来做
- Change iframe background color
- Change background color of the loaded page (same domain)
- 更改 iframe 背景颜色
- 更改加载页面的背景颜色(相同域)
Plain javascript
纯javascript
var iframe = document.getElementsByTagName('iframe')[0];
iframe.style.background = 'white';
iframe.contentWindow.document.body.style.backgroundColor = 'white';
jQuery
jQuery
$('iframe').css('background', 'white');
$('iframe').contents().find('body').css('backgroundColor', 'white');
回答by Andre
Put the Iframe between aside tags
将 iframe 放在旁边的标签之间
<aside style="background-color:#FFF">
your IFRAME
</aside>
<aside style="background-color:#FFF">
your IFRAME
</aside>