2012-08-03 56 views
1

我正在使用页面内的iframe,页面和iframe处于不同的域。该网站旨在用于移动设备,因此我通过html发布消息将页面的window.orientation属性传递给iframe。这是行得通的,但现在我需要一种方法来将iframe的window.orientation属性分配给从邮件中收到的值。是否有可能重新分配窗口属性,如.orientation,如果是的话如何?重新分配window.orientation?

所有帮助表示赞赏。

编辑:这样做的目的是让CSS的媒体查询设备的方向在iframe内工作。

+0

什么是你想通过重新分配该值达到什么目的?通过这个应该改变什么? – Bergi 2012-08-03 21:22:35

+0

我试图让媒体查询到设备的方向工作。如:@media(方向:风景)。 – 2012-08-03 21:25:06

+0

啊,好的。你可能应该在这个问题中提到这个问题:-) – Bergi 2012-08-03 21:30:29

回答

0

也许这可能是解决您的问题。

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);​ 

CSS

.profile{background:#f00} 
.landscape{background:#00f}​ 

DEMO