Iframe parent url

2019-07-29 12:54发布

How do I get an Iframe's parent window url using jQuery or JavaScript?

2条回答
再贱就再见
2楼-- · 2019-07-29 13:27

For script running in the iframe, use parent.location.href, although an iframe served from a different domain to its parent page will not be able to access this.

If you are on separate domains, there are a few alternative techniques that should work for you. In particular, using the window.name to pass data, or stacking iframes within iframes. Both, and more, are listed in this slideshow. Window.name is mentioned on slide 31. Especially check out slide 34 and on for the iframe stacking technique, which will enable bidirectional communication between differing origin iframes.

查看更多
一纸荒年 Trace。
3楼-- · 2019-07-29 13:41

Just include the url when opening the iframe.

<iframe 
src="http://foo.bar/iframe.html?iframeparentwindowurl=http://cheese.tv/parrot.html">
</iframe>
查看更多
登录 后发表回答