簡體   English   中英

重新分配window.orientation?

[英]Reassign window.orientation?

我正在頁面內使用iframe,並且頁面和iframe位於不同的域中。 該網站專用於移動設備,因此我正在通過html發布消息將頁面的window.orientation屬性傳遞給iframe。 那是可行的,但是現在我需要一種方法來將iframe的window.orientation屬性分配給從帖子消息接收的值。 是否可以重新分配.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);​

的CSS

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

演示

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM