Iframe 透明度问题

Iframe transparency issue

本文关键字:问题 透明度 Iframe      更新时间:2023-09-26

我有iframe来表示下拉菜单。 问题是当显示 iframe 时,我可以看到父页面的内容。

有没有办法不使iframe透明?

jQuery('<iframe id="accountframe" style="position: absolute; width: 290px; height:     140px;  margin-top: 0px;  margin-left: 0px; top:0px; left:0px; text-align:left overflow:hidden; allowTransparency:false"  src="test.jsp" ></iframe>').appendTo('#account');

我正在使用jQuery来动态添加/删除iframe。 我已经尝试了allowTransparency:false作为样式表,也允许Transparency="false"作为属性,但这两种方式都不起作用。

谢谢。

allowTransparency="true"怎么样?既然你希望它是透明的?

这也有助于在 iframe 上设置background-color:transparent,并确保加载到 iframe 中的页面不会在其正文中定义背景颜色。

你的代码中有一些错误: allowTransparency不是 CSS 属性。allowtransparency是 iframe 元素上的一个属性。你把allowTransparency写成一个CSS属性。

尝试使用此代码 -

jQuery('<iframe id="accountframe" style="position: absolute; width: 290px; height:140px; margin-top: 0px; margin-left: 0px; top:0px; left:0px; text-align:left overflow:hidden;" allowTransparency="false" src="test.jsp" ></iframe>').appendTo('#account');

有这方面的文章

正如你提到的,你也尝试allowTransparency="false"作为一个属性,但如果你想让你的IFrame透明。您需要在 Iframe 上设置allowTransparency="true"

确保IFRAME及其源BODY元素都应用了background:transparent样式规则:

<iframe frameborder="0" allowTransparency="true" style="background:transparent" ... ></iframe>

在源中:

<body style="background:transparent">

PS:上面的CSS样式只是例如内联的。

试试这个:

jQuery('<iframe id="accountframe" style="position: absolute; width: 290px; height:140px; margin-top: 0px; margin-left: 0px; top:0px; left:0px; text-align:left overflow:hidden;" allowTransparency="true" src="test.jsp" ></iframe>').appendTo('#account');