我尝试了多种访问父窗口方向变量的方法,但它似乎总是“未定义”或“空”。
以下是我尝试访问父窗口方向的不同方式:
parent.window.orientation
window.parent.orientation
window.opener.orientation
parent.document.orientation (shouldn't work, but I tried anyway)
parent.orientation
我也试过监听“orientationChanged”事件:
parent.document.addEventListener('orientationChanged',function() {
alert('orientation changed');
});
以上方法均无法检测 iframe 父级的方向。
不幸的是,我必须使用 iframe。我正在设计一个将放入跨域 iframe 的移动页面。最好,我希望能够从 iframe 中检测到方向变化,而不是让客户端在他们的页面上放置额外的 javascript。
最佳答案
关于javascript - 如何从跨域 iframe 中访问父窗口的 window.orientation?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7989570/