javascript - Detect orientation change from within cross-domain iframe -
so have .jsp page has iframe in it. content of iframe hosted on separate domain. on mobile device, i'm looking iframe detect orientation change , alter dimensions of content accordingly.
is there way add event listener content stored within iframe detect orientation change?
if content not within iframe, , accessed directly instead, call like: window.addeventlistener('orientationchange', functiontobecalled, false); catches orientation change , calls appropriate function. however, can't seem work within iframe. i've tried parent.addeventlistener, parent.window.addeventlistener, top.addeventlistener, etc. no avail.
from i've read sounds since cross-domain call have limited parent functionality available me, doomed fail?
any appreciated. thanks!
if own code of parent window can use cross document messsages solve this. send orientation parent window iframe. should work in cross domain scenario. tested on iphone 4.3 , android 2.2.
in parent window : register orientation changes , transfer iframe
window.addeventlistener("orientationchange", function(){ var iframe = document.getelementbyid("youriframe").contentwindow; iframe.postmessage({ orientation: window.orientation }, 'http://the.domain.of.the.iframe.com'); }, false)
in iframe : subscribe orientation changes parent
window.addeventlistener("message", function(e){ var neworientationvalue = e.data.orientation; alert(neworientationvalue); // <--- own logic here }, false)
check out more details : http://html5demos.com/postmessage2
Comments
Post a Comment