如何从嵌入在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;)

其他回答

您也可以通过这种方式使用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.
}

对于特定于浏览器的问题,还可以根据Dreamweaver添加frameborder=“0”hspace=“0“vspace=“1”marginheight=“2”marginwidth=“0”:

<iframe src="test.html" name="banner" width="300" marginwidth="0" height="300" marginheight="0" align="top" scrolling="No" frameborder="0" hspace="0" vspace="0">Browser not compatible. </iframe>

添加frameBorder属性,或使用边框宽度为0px;的样式;,或将边框样式设置为无。

使用以下3项中的任意一项:

浏览器不兼容</iframe><iframe src=“myURL”width=“300”height=“300”frameborder=“0”>浏览器不兼容</iframe><iframe src=“myURL”width=“300”height=“300”style=“border:none;”>浏览器不兼容</iframe>

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

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

使用HTML iframe frameborder属性

http://www.w3schools.com/tags/att_iframe_frameborder.asp

注意:IE使用frameBorder(cap B),否则将无法工作。但是,HTML5不支持iframeframeborder属性。因此,请改用CSS。

<iframe src="http://example.org" width="200" height="200" style="border:0">

也可以使用滚动属性删除滚动http://www.w3schools.com/tags/att_iframe_scrolling.asp

<iframe src="http://example.org" width="200" height="200" scrolling="no" style="border:0">

此外,您还可以使用HTML5中新增的无缝属性。iframe标签的无缝属性仅在Opera、Chrome和Safari中受支持。当出现时,它指定iframe看起来应该是包含文档的一部分(没有边框或滚动条)。目前,标签的无缝属性仅在Opera、Chrome和Safari中受支持。但在不久的将来,它将成为标准解决方案,并与所有浏览器兼容。http://www.w3schools.com/tags/att_iframe_seamless.asp