如何控制 Android/iPhone Web 应用程序的屏幕方向

发布于 2024-11-17 17:17:46 字数 180 浏览 10 评论 0原文

我正在为智能手机、Android 设备和 iPhone 创建网络应用程序。但我在想,如果网络应用程序只允许纵向屏幕方向会更好,这样无论用户以哪种方式握住手机,它都会始终保持纵向。

所以基本上我想知道的是如何使用 JavaScript、HTML 元标签、CSS 或 PHP 让 Android 和 iPhone 的屏幕始终保持纵向?

I am in the middle of creating a web app for smartphones, Android devices and iPhone's. But I was thinking that it would be better if the web app only allowed a portrait screen-orientation, so no matter which way the user is holding their phone it will always remain in portrait.

So basically what I want to know is how can I have the screen always remain in portrait for both Android and iPhone, using JavaScript, HTML Meta Tags, CSS, or PHP?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽清梦 2024-11-24 17:17:46

您可以读取窗口对象的“大小”、“宽度”,有时还可以读取“方向”属性。设置事件侦听器以在“调整大小”事件发生时触发 JavaScript 事件。

但据我所知,您实际上无法控制旋转。

这是一个演示:(我将其发布到我的网页,http://douglassims.org/rotation.html)

<head>

  <script>

  function checkRotation() {document.getElementById('orientationlabel').innerHTML='Orientation: ' + window.orientation + ' Width: ' + screen.width + ' Height: '+screen.height;} 
  function load() {window.addEventListener('resize', checkRotation, false);}
  </script>

</head>

<body onload='load();'>
  <center>
  <h2 id=orientationlabel>Nothing yet</h2>

</body>

You can read the "size", "width", and sometimes the "orientation" properties of the window object. Set an event listener to fire a javascript event when the "resize" event happens.

As far as I know, though, you can't actually control the rotation.

Here's a demo: (I posted it to my web page, http://douglassims.org/rotation.html)

<head>

  <script>

  function checkRotation() {document.getElementById('orientationlabel').innerHTML='Orientation: ' + window.orientation + ' Width: ' + screen.width + ' Height: '+screen.height;} 
  function load() {window.addEventListener('resize', checkRotation, false);}
  </script>

</head>

<body onload='load();'>
  <center>
  <h2 id=orientationlabel>Nothing yet</h2>

</body>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文