首页 文章

从IFrame中删除边框

提问于
浏览
634

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

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

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

23 回答

  • 5

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

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

    如果您放置iframe的页面的doctype是HTML5,那么您可以使用 seamless 属性,如下所示:

    <iframe src="..." seamless="seamless"></iframe>
    

    Mozilla docs on the seamless attribute

  • -1

    它简单只需在iframe标签中添加属性frameborder = 0 <iframe src="" width="200" height="200" frameborder="0"></iframe>

  • 5

    尝试

    <iframe src="url" style="border:none;"></iframe>
    

    这将删除框架的边框 .

  • 9

    在样式表中添加

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

    这也是一个可行的选择 .

  • 142

    添加 frameBorder 属性(注意 capital ‘B’ ) .

    所以它看起来像:

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

    对于浏览器特定问题,还要根据Dreamweaver添加 frameborder="0" hspace="0" vspace="0" marginheight="0" 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>
    
  • 7

    添加frameBorder属性,或使用border-width 0px;的样式,或将border样式设置为none .

    使用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>
    
  • 4

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

    <body style="margin:0px;">
    
  • 4

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

    <iframe src="test.html" style="width: 100%; height: 400px; border: 0"></iframe>
    
    • 注意CSS边框属性确实 not 在IE6,7或8中实现了所需的结果 .
  • 3

    还设置border =“0px”

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

    Style property can be used 对于HTML5,如果要删除框架或任何内容的平台,可以使用样式属性 . 如下所示

    代码在这里

    <iframe src="demo.htm" style="border:none;"></iframe>
    
  • 2

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

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

    * {
      padding:0px;
      margin:0px;
     }
    
  • 2
    <iframe src="URL" frameborder="0" width="100%" height="200">
    <p>Your browser does not support iframes.</p>
    </iframe>
    
    <iframe frameborder="1|0">
    
    (OR)
    
    <iframe src="URL" width="100%" height="300" style="border: none">Your browser 
    does not support iframes.</iframe>
    
    The <iframe> frameborder attribute is not supported in HTML5. Use CSS 
    instead.
    
  • 2
    iframe src="XXXXXXXXXXXXXXX"
    marginwidth="0" marginheight="0" width="xxx" height="xxx"
    

    适用于Firefox;)

  • 21

    用这个

    style="border:none;
    

    例:

    <iframe src="your.html" style="border:none;"></iframe>
    
  • 1

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

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

  • -1
    <iframe src="mywebsite" frameborder="0" style="border: 0px solid white;">HTML iFrame is not compatible with your browser</iframe>
    

    此代码应适用于HTML 4和5 .

  • 53

    使用HTML iframe frameborder属性

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

    注意:对于IE使用frame B order(cap B),否则将无效 . 但是,HTML5中不支持iframe frameborder属性 . 所以,请改用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

  • 6

    要删除边框,可以使用CSS border属性为none .

    <iframe src="myURL" width="300" height="300" style="border: none">Browser not compatible.</iframe>
    
  • 1033

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

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

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

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

    <iframe frameBorder="0" ></iframe>
    

相关问题