CSS perfect for iframe height adaptation (cross-domain support)

Source: Internet
Author: User

The powerful function of the IFRAME is not much to say, it is not only used by developers often, and hackers often use it, in short, the people know its powerful, but the IFRAME has a fatal "BUG" is the height of the IFRAME can not automatically adapt, which makes many people have a headache. Baidu or Google, a lot of solutions, but try, you will find a lot of problems: Poor browser compatibility , not adaptive , only support the same domain IFRAME and many other issues, especially the cross-domain iframe Highly adaptive problem. There is no way to find a viable solution on the web (the only one that mentions joining the proxy page has been tested and found useless). Isn't there really a workable solution? No, below the Xiao Ming son and everyone to share a powerful method, the code is as follows:

<style>
body {Margin-left:0px;margin-top:0px;margin-right:0px;margin-bottom:0px;overflow:hidden;}
</style>

<body>
<iframe src=\ ' #\ ' "//hi.baidu.com/' width=" 100% ' height= ' 100% ' frameborder= ' 0 ' name= "_blank" id= "_blank" ></ Iframe>

</body>

The code is powerful:

1. This method is perfectly compatible with ie6,7,8, fire Fox,chrome,opera and other mainstream browsers;

2. Same domain, cross-domain support;

3. Do not call any JS script;

Note three points.

1. The beginning of the file cannot be:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

Must be

2. Overflow:hidden in body style; Absolutely not omitted;

height= ' 100% ' in 3.Iframe and scroll bar cannot be set to No (default is yes, not set)

All right, try it now. 100% won't let you down.

CSS perfect for iframe height adaptation (cross-domain support)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.