开发者

How to control the screen-orientation for a Android/iPhone web app

开发者 https://www.devze.com 2023-03-16 00:52 出处:网络
I am in the middle of creating a web app for smartphones, Android devices and iPhone\'s. But I was thinking that it woul开发者_开发问答d be better if the web app only allowed a portrait screen-orienta

I am in the middle of creating a web app for smartphones, Android devices and iPhone's. But I was thinking that it woul开发者_开发问答d 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?


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>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号