如何从嵌入在web应用程序中的iframe中删除边框?iframe的一个示例是:

<iframe src="myURL" width="300" height="300">Browser not compatible.</iframe>

我希望从页面上的内容到iframe内容的转换是无缝的,假设背景颜色是一致的。目标浏览器仅为IE6,不幸的是,针对其他浏览器的解决方案将无济于事。


当前回答

iframe src="XXXXXXXXXXXXXXX"
marginwidth="0" marginheight="0" width="xxx" height="xxx"

适用于Firefox;)

其他回答

添加frameBorder属性(注意大写“B”)。

所以它看起来像:

<iframe src="myURL" width="300" height="300" frameBorder="0">Browser not compatible.</iframe>

也设置border=“0px”

 <iframe src="yoururl" width="100%" height="100%" frameBorder="0"></iframe>

1.通过内联样式集边框:0

 <iframe src="display_file.html" style="height: 400px; width:
   100%;border: 0;">HTML iFrame is not compatible with your browser
   </iframe>

2.通过标记属性框架边框集0

<iframe src="display_file.html" width="300" height="300" frameborder="0">Browser not compatible.</iframe>

3.如果我们有多个I帧,我们可以在内部或外部给class和Put css。

HTML格式:

<iframe src="display_file.html" class="no_border_iframe">
    HTML iFrame is not compatible with your browser 
</iframe>

CSS:

<style>
.no_border_iframe{
border: 0; /* or border:none; */
}
</style>

您也可以通过这种方式使用JavaScript来实现。它将在IE和其他浏览器中找到任何iframe元素并删除它们的边框(尽管您可以在非IE浏览器中设置“border:none;”样式,而不是使用JavaScript)。而且,即使在iframe生成并在文档中就位后使用它也会起作用(例如,以纯HTML而不是JavaScript添加的iframe)!

这似乎是有效的,因为IE在BOM中创建iframe之后,并不是在iframe元素上创建边框,而是在iframe的内容上创建边框。($@&*#@!!IE!!)

注意:如果父窗口和iframe来自相同的源(相同的域、端口、协议等),IE部分才会工作(当然)。否则,脚本将在IE错误控制台中出现“拒绝访问”错误。如果发生这种情况,您唯一的选择是在生成之前进行设置,正如其他人所指出的,或者使用非标准的frameBorder=“0”属性。(或者让IE看起来很奇怪——我现在最喜欢的选项;)

我花了好几个小时的工作才弄明白。。。

享受。:)

// =========================================================================
// Remove borders on iFrames

var iFrameElements = window.document.getElementsByTagName("iframe");
for (var i = 0; i < iFrameElements.length; i++)
{
  iFrameElements[i].frameBorder="0";   //  For other browsers.
  iFrameElements[i].setAttribute("frameBorder", "0");   //  For other browsers (just a backup for the above).
  iFrameElements[i].contentWindow.document.body.style.border="none";   //  For IE.
}

您可以在iframe代码中使用style=“border:0;”。这是HTML5中删除边框的推荐方法。

查看我的html5 iframe生成器工具,无需编辑代码即可自定义iframe。