How to implement highly adaptive iframe window _ javascript tips-js tutorial

Source: Internet
Author: User
This article mainly introduces how to implement highly adaptive iframe window. If you need it, you can refer to a webpage index.html in domainA and embed a webpage other.html in domainbthrough iframe.
Because the other.html page is displayed in iframe, and the page content will be dynamically increased or decreased, you need to remove the iframe scroll bar.
Cross-origin operations cannot be performed due to restrictions of the javascript same-origin policy, which makes the problem more difficult.
Refer to the online practice and introduce a proxy page, or called the intermediary agent.html, which belongs to domainA.
Then, use iframeto nest agent.html in other.html in domainB.

Now, the situation is as follows:
Index.html uses iframe to nest other.html
Other.html use iframe to nest agent.html
The third page, agent.html, is to follow the "same-origin policy" rules to complete parameter transfer in different domains!

Our ultimate goal is to remove the scroll bar and ensure that all the embedded page content is displayed.
1.get the actual height of the other.html page
2. Set the height to the src attribute of the embedded iframe.
3.in agent.html, extract the height value from the src attribute of the iframe.

In the following example, a technique is used to avoid using setInterval () to continuously set the iframe height.
The method is to add a timestamp to the SRC of iframe, so that the browser will reload agent.html every time.
Then let the js function invokeMethodInTopWindow () in agent. hml be executed.
2 html in domainA
Index.html

The Code is as follows:


# {Extends 'main.html '/}
# {Set title: 'home '/}

Window self-adaptation-removes the restriction of the same-origin policy, and uses the same-origin policy to remove the iframe scroll bar and dynamically adjust the window height so that it can display all content on the nested page.





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.