Set the height of the Cross-origin IFRAME

Source: Internet
Author: User

Cause

For example, if Domain A has a page in Domain B, but the length of the page in Domain B is unknown, a cannot set an accurate height.

PS: the IFRAME height setting auto is invalid.

Solution

 

For example,

(1) Add an IFRAME

PS: the innermost a page can call the method of the outermost a page, while the B page cannot call the outermost a page (because of the security restrictions of cross-origin ).

(2nd) When page B is complete, modify Src in the IFRAME where agent.html of.

SetTimeout (function () {VaR _ Height = $ ("# vs-source "). height (); var B _iframe = document. getelementbyid ("crossdomain_agent_iframe"); // iframe id of agent.html if (B _iframe) {var src = B _iframe.src.split ("#") [0]; src = SRC. split ("? ") [0]; B _iframe.src = SRC + "? "+ New date (). gettime () +" # "+ (B _height + (_ height-1000 ));}
},200 );

(3366agent.html Code call the code of the outermost layer a page to set the height of the B page

The agent.html code is as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Disadvantages

1. Modify page B, add an IFRAME, and set it automatically.

PS: in many cases, page B is a third-party page, which cannot be done either.

Set the height of the Cross-origin IFRAME

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.