我正在将一个小型 HTML/CSS/Javascript 驱动的网络杂志改编为 iPad 的 iApp,并带有出色的移动框架 PhoneGap。一切都很好,除了方向从纵向更改为横向模式。
我在 index.html(纵向)的标题中使用以下 Javascript 代码:
var isiPad = navigator.userAgent.match(/iPad/i) != null;
var isiPhone = navigator.userAgent.match(/iPhone/i) != null;
function updateOrientation() {
if (isiPad || isiPhone) {
switch (window.orientation) {
case 90:
window.location = "index_landscape.html";
break;
case -90:
window.location = "index_landscape.html";
break;
}
}
}
带有以下正文标签:
<body onorientationchange="updateOrientation();">
如果我将 iPad 旋转到横向模式,它不会更改为 index-landscape.html。
有谁知道问题出在哪里?是否可以更改 HTML 文件,同时在 PhoneGap 框架内更改方向?换句话说,我可以只使用一个带有PhoneGap的HTML文件(index.html)并且必须使用CSS来改变方向吗?
如果我使用 iPad Safari 浏览器将应用程序作为网站检出,则方向更改可以正常工作。
谢谢你的帮助!