csdnceshi53
Lotus@
采纳率50%
2008-09-15 17:43 阅读 410

从 IFrame 中删除边框

How do I remove the border from an iframe embedded in my web app? An example of the iframe is:

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

I would like the transition from the content on my page to the contents of the iframe to be seamless, assuming the background colors are consistent. The target browser is IE6 only and unfortunately solutions for others will not help.

转载于:https://stackoverflow.com/questions/65034/remove-border-from-iframe

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

19条回答 默认 最新

  • 已采纳
    csdnceshi55 ~Onlooker 2008-09-15 17:45

    Add the frameBorder attribute (note the capital ‘B’).

    So it would look like:

    <iframe src="myURL" width="300" height="300" frameBorder="0">Browser not compatible.</iframe>
    
    点赞 26 评论 复制链接分享
  • weixin_41568126 乱世@小熊 2008-11-02 21:29

    After going mad trying to remove the border in IE7, I found that the frameBorder attribute is case sensitive.

    You have to set the frameBorder attribute with a capital B.

    <iframe frameBorder="0" ></iframe>
    
    点赞 29 评论 复制链接分享
  • csdnceshi57 perhaps? 2008-09-15 17:54

    In addition to adding the frameBorder attribute you might want to consider setting the scrolling attribute to "no" to prevent scrollbars from appearing.

    <iframe src="myURL" width="300" height="300" frameBorder="0" scrolling="no">Browser not compatible. </iframe > 
    
    点赞 10 评论 复制链接分享
  • csdnceshi65 larry*wei 2017-07-01 08:31

    Try

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

    This will remove the border of your frame.

    点赞 10 评论 复制链接分享
  • csdnceshi53 Lotus@ 2017-07-22 09:10

    To remove border you can use CSS border property to none.

    <iframe src="myURL" width="300" height="300" style="border: none">Browser not compatible.</iframe>
    
    点赞 10 评论 复制链接分享
  • weixin_41568134 MAO-EYE 2013-07-03 15:06

    If the doctype of the page you are placing the iframe on is HTML5 then you can use the seamless attribute like so:

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

    Mozilla docs on the seamless attribute

    点赞 9 评论 复制链接分享
  • csdnceshi69 YaoRaoLov 2011-12-08 21:27

    As per iframe documentation, frameBorder is deprecated and using the "border" CSS attribute is preferred:

    <iframe src="test.html" style="width: 100%; height: 400px; border: 0"></iframe>
    
    • Note CSS border property does not achieve the desired results in IE6, 7 or 8.
    点赞 8 评论 复制链接分享
  • csdnceshi70 笑故挽风 2011-02-01 10:23

    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>
    
    点赞 7 评论 复制链接分享
  • weixin_41568127 ?yb? 2014-07-10 07:45

    Use the HTML iframe frameborder Attribute

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

    Note: use frameBorder (cap B) for IE, otherwise will not work. But, the iframe frameborder attribute is not supported in HTML5. So, Use CSS instead.

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

    you can also remove scrolling using scrolling attribute http://www.w3schools.com/tags/att_iframe_scrolling.asp

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

    Also you can use seamless attribute which is new in HTML5. The seamless attribute of the iframe tag is only supported in Opera, Chrome and Safari. When present, it specifies that the iframe should look like it is a part of the containing document (no borders or scrollbars). As of now, The seamless attribute of the tag is only supported in Opera, Chrome and Safari. But in near future it will be the standard solution and will be compatible with all browsers. http://www.w3schools.com/tags/att_iframe_seamless.asp

    点赞 6 评论 复制链接分享
  • csdnceshi74 7*4 2017-09-17 08:01

    Use this

    style="border:none;
    

    Example:

    <iframe src="your.html" style="border:none;"></iframe>
    
    点赞 6 评论 复制链接分享
  • weixin_41568134 MAO-EYE 2016-09-03 13:59
    <iframe src="mywebsite" frameborder="0" style="border: 0px solid white;">HTML iFrame is not compatible with your browser</iframe>
    

    This code should work in both HTML 4 and 5.

    点赞 5 评论 复制链接分享
  • csdnceshi55 ~Onlooker 2017-01-05 12:17

    also set border="0px "

     <iframe src="yoururl" width="100%" height="100%" frameBorder="0"></iframe>
    
    点赞 5 评论 复制链接分享
  • weixin_41568127 ?yb? 2017-02-11 11:27

    Style property can be used For HTML5 if you want to remove the boder of your frame or anything you can use the style property. as given below

    Code goes here

    <iframe src="demo.htm" style="border:none;"></iframe>
    
    点赞 5 评论 复制链接分享
  • weixin_41568183 零零乙 2012-01-23 21:50

    You can also do it with JavaScript this way. It will find any iframe elements and remove their borders in IE and other browsers (though you can just set a style of "border : none;" in non-IE browsers instead of using JavaScript). AND it will work even if used AFTER the iframe is generated and in place in the document (e.g. iframes that are added in plain HTML and not JavaScript)!

    This appears to work because IE creates the border, not on the iframe element as you'd expect, but on the CONTENT of the iframe--after the iframe is created in the BOM. ($@&*#@!!! IE!!!)

    Note: The IE part will only work (of course) if the parent window and iframe are from the SAME origin (same domain, port, protocol etc.). Otherwise the script will get "access denied" errors in the IE error console. If that happens, your only option is to set it before it is generated, as others have noted, or use the non-standard frameBorder="0" attribute. (or just let IE look fugly--my current favorite option ;) )

    Took me MANY hours of working to the point of despair to figure this out...

    Enjoy. :)

    // =========================================================================
    // 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.
             }
       }
    
    点赞 4 评论 复制链接分享
  • csdnceshi60 ℡Wang Yan 2016-03-16 06:17

    Add the frameBorder attribute (Capital ‘B’).

    <iframe src="myURL" width="300" height="300" frameBorder="0">Browser not compatible. </iframe>
    
    点赞 4 评论 复制链接分享
  • csdnceshi72 谁还没个明天 2014-06-12 19:43

    I tried all of the above and if that doesn't work for you try the below CSS resolved the issue for me. Which just tells the browsers to not add any padding or margin.

    * {
      padding:0px;
      margin:0px;
     }
    
    点赞 3 评论 复制链接分享
  • csdnceshi67 bug^君 2016-07-20 17:24

    If you are using the iFrame to fit the width and height of the entire screen, which I am assuming you are not based on the 300x300 size, you must also set the body margins to "0" like this:

    <body style="margin:0px;">
    
    点赞 3 评论 复制链接分享
  • csdnceshi72 谁还没个明天 2015-02-18 00:25

    In your stylesheet add

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

    This is also a viable option.

    点赞 2 评论 复制链接分享
  • csdnceshi66 必承其重 | 欲带皇冠 2015-10-23 03:23

    You can use style="border:0;" in your iframe code. That is the recommended way to remove border in HTML5.

    Check out my html5 iframe generator tool to customize your iframe without editing code.

    点赞 1 评论 复制链接分享

相关推荐