简体   繁体   中英

Iframe parent url

如何使用jQuery或JavaScript获取iframe的父窗口网址?

Just include the url when opening the iframe.

<iframe 
src="http://foo.bar/iframe.html?iframeparentwindowurl=http://cheese.tv/parrot.html">
</iframe>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM