简体   繁体   中英

Resizing cross-domain iframe

I've heard that it's possible to poll the url of an iframe for a hash to do something with it from the parent. What i need to do is set the height of a cross domain iframe dynamically. So whenever the height changes, the iframe sets its url to someurl#height. Now i need to access the hash (#height) from the parent, but it still won't let me. Using a proxy (iframe inside an iframe) is not an option in this case. Maybe i'm doing something wrong, how would you poll the url of an iframe?

iframe.contentWindow.location.href - security alert iframe.src - returns the url WITHOUT the hash

That's not usually the way it's done. What should be done, is the iframe calls window.parent.location = "#<iframe height>"; , setting the parent to have the hash value of the iframe height.

The parent page uses either the onhashchange event (IE, Firefox) to capture the change and then set the iframe's height or a timer that checks the hash value every 100ms or so. This is how Google CSE does it, at least.

See also my answer to a similar question:

Handle URL anchor change event in js

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