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;
  }
}
});
Sam Deering Sam Deering
Sam Deering is a Front-end Web Developer who specialises in JavaScript & jQuery. Sam is driven and passionate about sharing his knowledge to educate others.

  • 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.

Related books & courses
Available now on SitePoint Premium

Preview for $1