I’ve recently been getting stuck back into mobile app development in javascript. Being able to detect orientation change allows is really useful, It can be used to force users into a specific orientation by throwing up a notification panel saying “Please hold the device in landscape for this app”. Such scenarios are particularly important when developing games for mobile browsers.
<script> function doOnOrientationChange() { switch(window.orientation) { case -90: case 90: alert('landscape'); break; default: alert('portrait'); break; } } window.addEventListener('orientationchange', doOnOrientationChange); // Initial execution if needed doOnOrientationChange(); </script>
Leave A Comment