1
iframe可以識別其父網站的方向嗎?目前,CSS媒體查詢只在我的父站點工作。識別iFrame中的CSS方向
我試圖通過發送請求消息給我的iframe來解決這個問題,並改變與JavaScript的鏈接CSS文件:
父網站:
window.addEventListener("orientationchange", function(){
var iframe = document.getElementById("plan_iframe");
iframe.contentWindow.postMessage({orientation: window.orientation}, iframe.src);
}, false)
的iframe:
<link id="changing_css" rel="stylesheet" type="text/css" href=""/>
[...]
window.addEventListener("message", function(e){
var newOrientationValue = e.data.orientation;
if(newOrientationValue == 90 || newOrientationValue == -90){
document.getElementById('changing_css').href="css/vertretung_ios_landscape.css";
}
else{
document.getElementById('changing_css').href="css/vertretung_ios_portrait.css";
}
}, false)
此修復程序非常緩慢,因爲JavaScript需要一些時間來加載文件「onorientationchange」並應用更改。
css如何識別方向?
我有類似的問題。你有沒有找到解決方案?我試圖從一個iframe的CSS中的媒體查詢中檢測設備方向。 – Ringen
由於我的網站是一個iOS優化網站,我將媒體查詢更改爲 '@media screen和(min-width:900px)'。 這是最快和最簡單的解決方法。 –