CSS highly adaptive example of the implementation of the IFRAME

Source: Internet
Author: User
Tags html page


Antecedent: A project for statistical effect, the Consultation page window embedded into a separate empty page, in this page Riga a statistic, let people look at this page with direct access to the consultation page, lazy toss what JS, directly with CSS to get under, fortunately the demand is not too high. It's OK.

Consequences: Because of the little contact with the IFRAME, almost useless, so at that time on Google, Baidu, also do not remember what was found at that time what content, anyway, the demand is not too strong, directly with CSS to solve

<! DOCTYPE html>

Visual looks like the table removed is also can drop, no test of OH.

Here are two ways to do it. One is placed on the same page as the IFRAME, one is placed on the test.html page.
Be careful not to put the wrong place.


IFRAME code, note to write ID

<iframe src= "test.html" id= "main" width= "M" height= "" frameborder= "0" scrolling= "Auto" ></iframe>
jquery Code 1:
//NOTE: The following code is placed in the test.html call
$ (window.parent.document). Find ("#main"). Load (function () {
var main = $ (window.parent.document). Find ("#main");
var thisheight = $ (document). Height () +30;
Main.height (thisheight);
});

jquery Code 2:

Note: The following code is placed on the same page as the IFRAME call

$ ("#main"). Load (function () {

var mainheight = $ (this). Contents (). Find ("Body"). Height () +30;

$ (this). Height (mainheight);

});

HTML code:

<iframe src= "http://www.111cn.net/" id= "Iframepage" name= "Iframepage" frameborder=0 "Scrolling=no" width= "100%" Onload= "Iframeheight ()" ></iframe>
JavaScript code:
<script type= "Text/javascript"   JavaScript ">
function Iframeheight () {
var ifm= document.getelementbyid (" Iframepage ");   
var subweb = document.frames document.frames["Iframepage"].document:ifm.contentdocument;  
if (IFM!= null && subweb!= null) {
ifm.height = subWeb.body.scrollHeight;
}
}
</script>

Related Article

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.