Page domain relationship:
The domain A to which the main page a.html belongs: www.VeVb.com
The domain B to which the iframed page b.html belongs: www.jb51.cn, assuming address: http://www.jb51.cn/b.html
Realize the effect:
The page a.html under domain name A is embedded in the page b.html under domain name B through an iframe. Since the width and height of b.html are unpredictable and will change, the adaptive size of the iframe in a.html is required.
The nature of the problem:
The problem of js accessing cross-domain iframes is that to control the height and width of the iframe in a.html, you must first read the size of b.html. A and B do not belong to the same domain. For security reasons, the browser restricts cross-domain access to js and cannot read the height and width of b.html.
Solution:
The proxy proxy page c.html belongs to the same domain A as a.html. c.html is a good intermediate proxy page provided under the A domain. Assume that the address of c.html is www.VeVb.com/c.html, it is responsible for reading the width and height values in location.hash, and then setting the width and height of the iframe in a.html under the same domain as it.
The code is as follows:
a.html code
First, b.html was introduced through iframe in a.html
<iframe id=b_iframe height=0″ width=0″ src=http://www.jb51.cn/b.html frameborder=no border=0px marginwidth=0″ marginheight=0″ scrolling=no allowtransparency=yes ></iframe>
b.html code
Copy the code