Home > Web Front-end > JS Tutorial > How to make iframe adaptive to front-end height in jquery

How to make iframe adaptive to front-end height in jquery

php中世界最好的语言
Release: 2018-04-26 15:27:18
Original
1686 people have browsed it

This time I will bring you jqueryHow to make iframe adapt to the height of the front end, jquery makes the iframe adapt to the height of the front end. take a look. iframe code, pay attention to write ID

<iframe src="test.html" id="main" 
width
="700" 
height
="300" frameborder="0" scrolling="auto"></iframe>
Copy after login

jquery code one:

//注意:下面的代码是放在test.html调用 
$(window.parent.
document
).find("#main").load(function(){ 
var main = $(window.parent.document).find("#main"); 
var thisheight = $(document).height()+30; 
main.height(thisheight); 
});
Copy after login

jquery code two:

//注意:下面的代码是放在和iframe同一个页面调用 
$("#main").load(function(){ 
var mainheight = $(this).contents().find("body").height()+30; 
$(this).height(mainheight); 
});
Copy after login

I believe you have mastered it after reading the case in this article For more exciting methods, please pay attention to other related articles on the php Chinese website!

Recommended reading:

JQuery cross-domain operation DOM method in iframe


What are the implementation methods of AJAX secondary linkage

The above is the detailed content of How to make iframe adaptive to front-end height 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