我正在调用来自JavaScript函数的两个HTML文件,我希望,当iPad处于肖像模式时,它应该加载portrati.html
,并且在Landscapde模式下,它应该打开ladnscape.html
使用以下代码第一次加载时,它在浏览器上工作,但是当我们更改方向时,它不会更改文件。
<SCRIPT language="JavaScript">
if(window.innerHeight < window.innerWidth){
window.location="Landscape/index.html";
}
else if (window.innerHeight > window.innerWidth){
window.location="Potrait/index.html";
}
</SCRIPT>
iOS上的Safari有一个事件:
window.onorientationchange
您可以将其用于检测更改。
window.onorientationchange = function() {
switch (window.orientation) {
case 0: // portrait
window.location = "Portrait/index.html";
break;
case 90: // Landscape
window.location = "Landscape/index.html";
break;
case -90: // Other way round
window.location = "OtherLandscape/index.html";
break;
}
}
这仅是自iOS 4以来运行的。
window.onresize = function() {
if(window.innerHeight < window.innerWidth){
window.location="Landscape/index.html";
}
else if (window.innerHeight > window.innerWidth){
window.location="Potrait/index.html";
}
}
您的代码的复制pasta。