Solve the Problem of location. hash cross-domain iframe adaptive

Source: Internet
Author: User

Page domain relationship:

Main Page a.html Domain A: www.taobao.com
The Domain B: www.alimama.com of the page B .html of iframe, assuming address: http://www.alimama.com/ B .html

Effect:

The iframe adaptive size in dimensions.

Problem nature:

The height and width of the shard.

Solution:

Link to the proxy page c.html and a.html are in the same domain A, and c.html is the intermediate proxy page under the domain. The address of c.html is incorrect.

The Code is as follows:

A.html code

First, a.html introduced B .html through iframe.

<Iframe id = "B _iframe" height = "0" width = "0" src = "http://www.alimama.com/ B .html" frameborder =" no "border =" 0px "marginwidth =" 0 "marginheight =" 0 ""scrolling =" no "allowtransparency =" yes "> </iframe>

B .html code

<Script type = "text/javascript">
Var B _width = Math.max(document.doc umentElement. clientWidth, document. body. clientWidth );
Var B _height = Math.max(document.doc umentElement. clientHeight, document. body. clientHeight );
Var c_iframe = document. getElementById ("c_iframe"); // bkjia.com
C_iframe.src = c_iframe.src + "#" + B _width + "|" + B _height; // http://www.taobao.com/c.html#width | height"
}
</Script>
<! -Js reads B .html's width and height, and sets the read width and height to the hash of src in c.html on the central proxy page in the same domain as a.html->
<Iframe id = "c_iframe" height = "0" width = "0" src = "http://www.taobao.com/c.html" style =" display: none "> </iframe>

C.html code

<Script type = "text/javascript">
Var B _iframe = parent.parent.doc ument. getElementById ("B _iframe ");
Var hash_url = window. location. hash;
Var hash_width = hash_url.split ("#") [1]. split ("|") [0] + "px ";
Var hash_height = hash_url.split ("#") [1]. split ("|") [1] + "px ";
B _iframe.style.width = hash_width;
B _iframe.style.height = hash_height;
</Script>

The iframein a.html can be regarded as the width and height of B .html.
Other cross-origin operations similar to js can also be solved in this way

Original: http://ued.alimama.com /? P = 197

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.