Html 更改iframe问题的背景色
如果Html 更改iframe问题的背景色,html,iframe,background-color,Html,Iframe,Background Color,如果,我需要将显示页面的背景色更改为白色。可能吗?现在原来网站的背景是灰色的 <iframe allowtransparency="true" style="background-color: Snow;" src="http://zingaya.com/widget/9d043c064dc241068881f045f9d8c151" frameborder="0" height="184" width="100%"> </iframe> 我想更改加载页面
,我需要将显示页面的背景色更改为白色。可能吗?现在原来网站的背景是灰色的
<iframe allowtransparency="true" style="background-color: Snow;" src="http://zingaya.com/widget/9d043c064dc241068881f045f9d8c151" frameborder="0" height="184" width="100%">
</iframe>
我想更改加载页面的背景可以这样更改
背景:
我认为不可能更改您在iframe中加载的页面的背景。JavaScript是您所需要的。如果在加载页面时正在加载iframe,请使用onload事件插入iframe的测试。如果iframe是实时插入的,那么在插入时创建一个回调函数,并钩住需要执行的任何操作:)将iframe放在两个标记之间
你的IFRAME
您可以使用javascript来完成
var iframe = document.getElementsByTagName('iframe')[0];
iframe.style.background = 'white';
iframe.contentWindow.document.body.style.backgroundColor = 'white';
- 更改iframe背景色
- 更改加载页面的背景颜色(同一域)
var iframe = document.getElementsByTagName('iframe')[0];
iframe.style.background = 'white';
iframe.contentWindow.document.body.style.backgroundColor = 'white';
jQuery
$('iframe').css('background', 'white');
$('iframe').contents().find('body').css('backgroundColor', 'white');
在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);
我希望这有帮助 这是可能的。使用vanilla Javascript,您可以使用下面的函数作为参考
function updateIframeBackground(iframeId) {
var x = document.getElementById(iframeId);
var y = (x.contentWindow || x.contentDocument);
if (y.document) y = y.document;
y.body.style.backgroundColor = "#2D2D2D";
}
我想更改加载页面的背景。如果您能提供代码(我不擅长Java脚本),那就太好了。我可能想解释一下,将iframe放在一旁将如何更改其背景颜色