Javascript 重新指定窗口方向?

Javascript 重新指定窗口方向?,javascript,html,css,orientation,Javascript,Html,Css,Orientation,我在页面中使用iframe,页面和iframe位于不同的域上。该站点是为移动设备设计的,因此我通过一条html post消息将页面的window.orientation属性传递给iframe。这是可行的,但现在我需要一种方法将iframe的window.orientation属性指定给从post消息接收到的值。是否可以重新指定窗口属性,如.orientation,如果可以,如何重新指定 感谢所有的帮助 编辑:这样做的目的是让css媒体查询到设备的方向,以便在iframe中从内部工作。也许这可以解

我在页面中使用iframe,页面和iframe位于不同的域上。该站点是为移动设备设计的,因此我通过一条html post消息将页面的window.orientation属性传递给iframe。这是可行的,但现在我需要一种方法将iframe的window.orientation属性指定给从post消息接收到的值。是否可以重新指定窗口属性,如.orientation,如果可以,如何重新指定

感谢所有的帮助


编辑:这样做的目的是让css媒体查询到设备的方向,以便在iframe中从内部工作。

也许这可以解决您的问题

JS

var currentWidth = 0;

function updateLayout() {
    if (window.innerWidth != currentWidth) {
        currentWidth = window.innerWidth;

        var orient = currentWidth == 320 ? "profile" : "landscape";
        document.body.setAttribute("class", orient);
    }
}

setInterval(updateLayout, 400);
window.addEventListener("resize", updateLayout, false);
window.addEventListener("orientationchange", updateLayout, false);​
.profile{background:#f00}
.landscape{background:#00f}​
CSS

var currentWidth = 0;

function updateLayout() {
    if (window.innerWidth != currentWidth) {
        currentWidth = window.innerWidth;

        var orient = currentWidth == 320 ? "profile" : "landscape";
        document.body.setAttribute("class", orient);
    }
}

setInterval(updateLayout, 400);
window.addEventListener("resize", updateLayout, false);
window.addEventListener("orientationchange", updateLayout, false);​
.profile{background:#f00}
.landscape{background:#00f}​

通过重新分配该值,您试图实现什么目标?通过这种方式应该改变什么?我正在尝试让媒体查询到设备的方向来工作。比如:@media(方位:横向)。啊,好的。你可以在问题中提到这一点,让它有意义:-)