1

ページ内で iframe を使用していますが、ページと iframe は異なるドメインにあります。このサイトはモバイル デバイスを対象としているため、ページの window.orientation プロパティを HTML 投稿メッセージを介して iframe に渡しています。それは機能していますが、iframe の window.orientation プロパティを投稿メッセージから受け取った値に割り当てる方法が必要です。.orientation のようなウィンドウ プロパティを再割り当てすることは可能ですか?

すべての助けに感謝します。

編集: これの目的は、CSS メディア クエリをデバイスの向きに取得して、iframe 内から機能させることです。

4

1 に答える 1

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}​

デモ

于 2012-08-13T21:07:13.920 に答える