【发布时间】:2010-08-23 13:14:58
【问题描述】:
我正在将一个小型的 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 框架内更改方向? 换句话说,我可以只使用 一个 HTML 文件 (index.html) 和 PhoneGap 并且必须使用 CSS 来改变方向吗?
如果我使用 iPad Safari 浏览器将应用程序作为网站检出,则方向更改可以正常工作。
感谢您的帮助!
【问题讨论】:
-
发现window.orientation 在Android 2.2 和Droid X 上使用PhoneGap 对我有用。
标签: javascript iphone ipad cordova