Featured post
javascript - How can I dynamically resize my iframe, avoiding the browser security crossdomain restrictions? -
we have embeddable badge creates iframe. needs dynamic size; changes size based on data loaded 3rd party api or our database. it's not known height before loads.
it's invoked tag loads script our server, creates iframe set specific src.
on own machine, within iframe can do
window.parent.document.getelementbyid('my_frame').style.height=new_calculated_height+'px';
but of course when it's embedded in page different iframe src, fails due crossdomain restrictions ('unsafe access attempt' error in ff, etc.).
as we're loading script host page full access, kind of silly.
basically, need variable, new height, iframe host page.
could in reverse maybe? have function on host page ask iframe it's element's offsetheight?
this can real pain in butt working cross browser.
i suggest use easyxdm (http://easyxdm.net/). it's javascript library uses postmessage transport on modern browsers , uses javascript ninja on old browsers.
the library allows communicate between iframe , it's parent if aren't on same domain.
the library supports way down ie6!
edit: there's example resize height of iframe dynamically once content loaded: http://easyxdm.net/wp/2010/03/17/resize-iframe-based-on-content/
- christian
- Get link
- X
- Other Apps
Comments
Post a Comment