Javascript Mobile Orientation Detection


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. detectOrientation();
  2. window.onorientationchange = detectOrientation;
  3. function detectOrientation(){
  4. if(typeof window.onorientationchange != 'undefined'){
  5. if ( orientation == 0 ) {
  6. //Do Something In Portrait Mode
  7. }
  8. else if ( orientation == 90 ) {
  9. //Do Something In Landscape Mode
  10. }
  11. else if ( orientation == -90 ) {
  12. //Do Something In Landscape Mode
  13. }
  14. else if ( orientation == 180 ) {
  15. //Do Something In Landscape Mode
  16. }
  17. }
  18. }

URL: http://www.devinrolsen.com/javascript-mobile-orientation-detection/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.