现在可以使用 HTML5 Web 应用程序清单。见下文。
原答案:
您无法将网站或 Web 应用程序锁定在特定方向。它违背了设备的自然行为。
You can detectCSS3 媒体查询的设备方向如下:
@media screen and (orientation:portrait) {
// CSS applied when the device is in portrait mode
}
@media screen and (orientation:landscape) {
// CSS applied when the device is in landscape mode
}
或者通过绑定 JavaScript 方向更改事件,如下所示:
document.addEventListener("orientationchange", function(event){
switch(window.orientation)
{
case -90: case 90:
/* Device is in landscape mode */
break;
default:
/* Device is in portrait mode */
}
});
2014 年 11 月 12 日更新:现在可以使用 HTML5 Web 应用程序清单。
正如上所解释的html5rocks.com,您现在可以使用强制方向模式manifest.json
file.
您需要将这些行包含到 json 文件中:
{
"display": "standalone", /* Could be "fullscreen", "standalone", "minimal-ui", or "browser" */
"orientation": "landscape", /* Could be "landscape" or "portrait" */
...
}
您需要将清单包含到您的 html 文件中,如下所示:
<link rel="manifest" href="manifest.json">
不太确定 Web 应用程序清单上对锁定方向模式的支持是什么,但 Chrome 肯定是有的。当我有信息时会更新。