iframe 跨域问题
www.a.com(A网站) 下面的两个页面:
a.html
c.html
A 网站的网页 a.html 通过 iframe 包含了 B 网站的网页 b.html,
a.html 中的一行内容: <iframe src="http://www.b.com/b.html"></iframe>
问题:在 b.html 中想修改 a.html 的内容,但是有跨域的问题,因为 a.html 和 b.html 不在一个域名下,即使仅是端口不同,也算是跨域。
www.b.com(B网站)
b.html
解决方案:
在 b.html 再通过一个 iframe 引入 A网站的一个网页 c.html,把需要处理的代码放在此页面中。
b.html 中的一行内容: <iframe src="http://www.a.com/c.html"></iframe>
这样 a.html 和 c.html 是在同一个域名下,就可以在 c.html 下通过 js 修改 a.html 的内容了
在 c.html 中可以通过 parent.parent.document 访问 a.html 的文档根对象