jquery Library implements IFRAME adaptive content height and width

Source: Internet
Author: User
Tags jquery library

JavaScript native and jquery libraries implement IFRAME adaptive content heights and widths---Use jquery's code!

<iframe src= "index.php" id= "Mainiframe" name= "Mainiframe" width= "100%" frameborder= "0" scrolling= "no" marginwidth= "0" marginheight= "0" ></iframe>
The code based on the jquery library is well implemented:
<script language= "javascript" type= "Text/javascript" >
$ (document). Ready (function () {
$ ("#mainframe"). Load (function () {
$ (this). Height (0); Control iframe height initialization for each refresh
var height = $ (this). Contents (). Height () + 10;
$ (this). Height (height < 500:height);

Based on the JS native code implementation:
<script language= "JavaScript" >
if (window.parent.length>0) {window.parent.document.all.mainframe.style.height=document.body.scrollheight;}
Just add the above paragraph after you've been called by the IFRAME </body>!
This can also control the height of the iframe automatically grows with the content
<iframe name= "web" width= "100%" frameborder=0 height= "100%" src= "index.php" id= "web" onload= "this.height= Web.document.body.scrollheight+20 "></iframe>jquery Library implements IFRAME adaptive content height and width

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.