Home > Web Front-end > JS Tutorial > body text

How to implement iframe adaptive height and width in jquery

php中世界最好的语言
Release: 2018-04-24 14:44:32
Original
1871 people have browsed it

This time I will bring you jqueryHow to implement iframe adaptive height and width, jquery implements iframe adaptive height and widthWhat are the precautions, the following is a practical case, one Get up and take a look.

javascriptNative and jquery libraries implement iframe adaptive content height and width---jQuery code is recommended!

‍<iframe src="index.php" id="mainiframe" name="mainiframe" width="100%" frameborder="0" scrolling="no" marginwidth="0" marginheight="0"></iframe>
Copy after login

The code based on the Jquery library is easy to implement:

<script language="javascript" type="text/javascript"> 
$(document).ready(function(){ 
$("#mainframe").load(function(){ 
$(this).height(0); //用于每次刷新时控制IFRAME高度初始化 
var height = $(this).contents().height() + 10; 
$(this).height( height < 500 ? 500 : height ); 
}); 
}); 
</script>
Copy after login

‍The implementation based on the JS native code:

<script language="javascript"> 
if (window.parent.length>0){window.parent.document.all.mainframe.style.height=document.body.scrollHeight;} 
</script>
Copy after login

Just add the file you are called by iframe Then add the above paragraph!
This can also control the height of the iframe to automatically grow with the amount of content

<iframe name="web" width="100%" frameborder=0 height="100%" src="index.php" id="web" onload="this.height=web.document.body.scrollHeight+20" ></iframe>
Copy after login

jquery library implements iframe adaptive content height and width

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!

Recommended reading:

Detailed explanation of the steps for Jquery to operate js arrays and objects

Detailed explanation of the steps for jquery to remove selected values ​​from an array

The above is the detailed content of How to implement iframe adaptive height and width in jquery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!