从IFrame中删除边框

Joe*_*elB 678 html css iframe noborder internet-explorer-6

如何从__CODE__我的网络应用程序中嵌入边框中删除边框?一个例子__CODE__是:

<iframe src="myURL" width="300" height="300">Browser not compatible.</iframe>
Run Code Online (Sandbox Code Playgroud)

__CODE__假设背景颜色一致,我希望从页面上的内容过渡到无缝的内容.目标浏览器只是IE6,不幸的是其他人的解决方案无济于事.

Dav*_*rab 1087

添加frameBorder属性(注意大写'B').

所以它看起来像:

<iframe src="myURL" width="300" height="300" frameBorder="0">Browser not compatible.</iframe>
Run Code Online (Sandbox Code Playgroud)

  • @MartinAndersson http://caniuse.com/#feat=iframe-seamless表示它根本不受支持. (14认同)
  • 使用[标记验证服务](http://validator.w3.org/check)验证文档时,`frameBorder`会导致错误,因为它不符合HTML5:_ iframe元素上的frameborder属性已过时.改为使用CSS.在HTML5中我会设置一个CSS属性`border:0`.有没有办法使其向后兼容而不会导致验证错误? (11认同)
  • 花了一分钟时间在JavaScript中弄清楚你只需要element.frameBorder = 0.没有.style并使用0,而不是'0' (3认同)
  • 这里的答案是正确的,但是建议使用无缝属性的评论不再正确。无缝属性已从规范中删除:https://www.w3.org/TR/2014/REC-html5-20141028/embedded-content-0.html#the-if​​rame-element (3认同)
  • @MatthewT.Baker 当然,请参阅我对有关此属性的其他许多问题之一的回答:http://stackoverflow.com/a/20719286/1016716 哎呀,我看到我忘记了那里的大写 B;我来编辑。 (2认同)
  • 请注意,虽然 JavaScript 属性是带有大写 B 的“frameBorder”,但 HTML 属性实际上始终不区分大小写。在 XHTML 中,它应该全部小写“frameborder”。 (2认同)

Ada*_*dam 142

在试图删除IE7中的边框之后,我发现frameBorder属性区分大小写.

您必须使用大写B设置frameBorder属性.

<iframe frameBorder="0" ></iframe>
Run Code Online (Sandbox Code Playgroud)

  • 这太荒谬了!虽然很好.所以再次给我省了几个小时的麻烦:) (12认同)

小智 74

根据iframe文档,不推荐使用frameBorder,并且首选使用"border"CSS属性:

<iframe src="test.html" style="width: 100%; height: 400px; border: 0"></iframe>
Run Code Online (Sandbox Code Playgroud)
  • 注意CSS边框属性在IE6,7或8 中没有达到预期的效果.


xen*_*nox 54

除了添加frameBorder属性之外,您可能还需要考虑将滚动属性设置为"no"以防止出现滚动条.

<iframe src="myURL" width="300" height="300" frameBorder="0" scrolling="no">Browser not compatible. </iframe > 
Run Code Online (Sandbox Code Playgroud)

  • 风格="溢出:隐藏" (3认同)

小智 21

For browser specific issues also add frameborder="0" hspace="0" vspace="0" marginheight="0" marginwidth="0" according to Dreamweaver:

<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>
Run Code Online (Sandbox Code Playgroud)


Shu*_*dal 9

使用HTML iframe frameborder属性

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

注意:对于IE 使用帧B顺序(上限B),否则将无效.但是,HTML5中不支持iframe frameborder属性.所以,请改用CSS.

<iframe src="http://example.org" width="200" height="200" style="border:0">
Run Code Online (Sandbox Code Playgroud)

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

<iframe src="http://example.org" width="200" height="200" scrolling="no" style="border:0">
Run Code Online (Sandbox Code Playgroud)

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


Sha*_*shy 9

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

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


Arp*_*ini 9

Style属性可用于 HTML5如果要删除框架的boder或任何可以使用style属性的内容.如下所示

代码在这里

<iframe src="demo.htm" style="border:none;"></iframe>
Run Code Online (Sandbox Code Playgroud)


Har*_*hul 7

添加frameBorder属性(Capital'B').

<iframe src="myURL" width="300" height="300" frameBorder="0">Browser not compatible. </iframe>
Run Code Online (Sandbox Code Playgroud)


Fir*_*tal 6

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

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

注意:如果父窗口和iframe来自SAME源(相同的域,端口,协议等),则IE部分仅起作用(当然).否则,脚本将在IE错误控制台中出现"访问被拒绝"错误.如果发生这种情况,您唯一的选择是在生成之前设置它,就像其他人注意到的那样,或者使用非标准的frameBorder ="0"属性.(或者只是让IE看起来很脏 - 我目前最喜欢的选项;))

花了我几个小时的工作到绝望的地方来解决这个问题......

请享用.:)

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

if (window.document.getElementsByTagName("iframe"))
   {
      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.
         }
   }
Run Code Online (Sandbox Code Playgroud)


Dav*_*ite 6

如果您放置iframe的页面的doctype是HTML5,那么您可以seamless像这样使用该属性:

<iframe src="..." seamless="seamless"></iframe>
Run Code Online (Sandbox Code Playgroud)

Mozilla有关无缝属性的文档

  • *接缝*就像一个好主意,但遗憾的是没有得到很好的支持.http://caniuse.com/#search=seamless (4认同)
  • 它根本不受支持. (4认同)
  • 它甚至被从文档中删除 (2认同)

小智 6

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

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

<iframe src="myURL" width="300" height="300" style="border-width:0px;">Browser not compatible.</iframe>

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

<iframe src="myURL" width="300" height="300" style="border:none;">Browser not compatible.</iframe>
Run Code Online (Sandbox Code Playgroud)


小智 5

我尝试了以上所有内容,如果这对您不起作用,请尝试下面的CSS解决了我的问题.这只是告诉浏览器不添加任何填充或边距.

* {
  padding:0px;
  margin:0px;
 }
Run Code Online (Sandbox Code Playgroud)


小智 5

在你的样式表中添加

{
  padding:0px;
  margin:0px;
  border: 0px

}
Run Code Online (Sandbox Code Playgroud)

这也是一个可行的选择.


小智 5

如果您使用 iFrame 来适应整个屏幕的宽度和高度,我假设您不是基于 300x300 尺寸,您还必须将正文边距设置为“0”,如下所示:

<body style="margin:0px;">
Run Code Online (Sandbox Code Playgroud)


小智 5

<iframe src="mywebsite" frameborder="0" style="border: 0px solid white;">HTML iFrame is not compatible with your browser</iframe>
Run Code Online (Sandbox Code Playgroud)

此代码应该在 HTML 4 和 5 中都可以使用。