简体   繁体   English

如何从跨域iframe中访问父窗口的window.orientation?

[英]How can I access window.orientation of parent window from inside a cross-domain iframe?

I have tried various ways of accessing a parent window's orientation variable, but it always seems to be either "undefined" or "null". 我尝试了各种访问父窗口的方向变量的方法,但它似乎总是“未定义”或“空”。

Here are the different ways I've tried accessing the parent window's orientation: 这是我尝试访问父窗口方向的不同方法:

parent.window.orientation
window.parent.orientation
window.opener.orientation
parent.document.orientation (shouldn't work, but I tried anyway)
parent.orientation

I've also tried listening for the "orientationChanged" event: 我还尝试了侦听“ orientationChanged”事件:

parent.document.addEventListener('orientationChanged',function() {
    alert('orientation changed');
    });

None of the above methods are able to detect the orientation of an iframe parent. 以上方法均无法检测iframe父对象的方向。

Unfortunately, I am required to use iframes. 不幸的是,我需要使用iframe。 I am designing a mobile page that will be placed into a cross-domain iframe. 我正在设计一个将放置在跨域iframe中的移动页。 Preferably, I want to be able to detect an orientation change from within the iframe instead of having the client put extra javascript on their page. 最好是,我希望能够从iframe中检测方向变化,而不是让客户端在页面上放置额外的javascript。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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