JavaScript
Article

JavaScript Capture IOS7 iPad Screen Orientation Change

By Sam Deering

Code snippet to capture ipad device change (IOS7) tested.

jQuery(document).ready(function($) {
//capture ipad device change (IOS7) tested.
function doOnOrientationChange()
{
  // alert(window.orientation);
  switch(window.orientation)
  {
    case 0:
    case 90:
      alert('portrait');
      $('html').removeClass('landscape').addClass('portrait');
      break;
    case -90:
      alert('landscape');
      $('html').removeClass('portrait').addClass('landscape');
      break;
    default:
      break;
  }
}
});
  • Dustin

    This is a function which detects the current orientation on page loads, and then adds a class to the document. It in no way detects if there is an orientation change after the document has already loaded.

    • http://jquery4u.com/ jQuery4u

      It works for me, if you know of a better way please share.

Recommended

Learn Coding Online
Learn Web Development

Start learning web development and design for free with SitePoint Premium!

Get the latest in JavaScript, once a week, for free.