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