Iframe adaptive height

Source: Internet
Author: User
How can I make the iframe adaptive content height? I searched many solutions on the Internet, but none of them worked. What should I do? Who has a good idea?

My example is very simple. a blank page references the homepage of Sohu. how does the framework adapt to the height?


I just want to give an example, not leeching. Thank you.


Reply to discussion (solution)

You have found a lot of answers and try again to change the iframe address to the same directory as the current page.
Also, you can write iframein 1.html, open 2.html, and write content in 2.html. At least, both files are yours and can be accessed by the same domain name.
Try the answer.

I don't want to write code for you. I just want to provide ideas. Because the page height of Sohu is unpredictable, you have to use js on the parent page to regularly check the content height of the subpage (Sohu) (simple, check the height of the document.) once the height changes, adjust the iframe height in js on the parent page, generally, according to the user's network latency, Sohu's page should be fully loaded in three or four seconds, and the height here will be basically constant.

I still did not solve the problem, and it is estimated that it is difficult to solve it.

1. js is required to modify the ifame height. I believe you have found the code.
2. js cannot operate cross-origin controls. You are not SOHU. Obviously, Sohu in iframe is cross-origin, so modification failed.
3. you can achieve your goal only by converting Sohu from cross-origin to non-Cross-origin.
4. php provides a way to obtain remote data (including web pages). you only need to apply the data flexibly.

It is very clear, that is,. I will learn how to get it.

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.