1

I'm trying to alert mobile device users on my site to use their devices in landscape mode. I have an alert pop up but it seems to be getting caught in an infinite loop. How would I go about stopping that loop after the user has clicked ok?

Here is the code:

window.ondeviceorientation = detectIPadOrientation;
function detectIPadOrientation () 
{
    if ( orientation == 0 || orientation == 180 ){
        alert ('Please use your iPad in landscape mode'); 
    }
}
Pointy
  • 405,095
  • 59
  • 585
  • 614
Allan Moody
  • 31
  • 1
  • 1
  • 5
  • 2
    FWIW, telling people what to do with their device isn't exactly a UX "best practice." – Pointy May 20 '13 at 16:03
  • It's only for a specific page not for the entire site. @Pointy – Allan Moody May 20 '13 at 16:08
  • Perhaps this has to do with how quickly iOS rechecks screen position - over and over I presume. You could set a flag that would ensure it only pops up one time. `var pop=true;` `if(orientation... && pop){alert(...); pop=false};}` – rGil May 20 '13 at 16:11

2 Answers2

2

The following code will send an alert based on screen orientation. The alert will only be sent if the screen is in landscape mode.

window.onload = function() {
    if ( window.orientation == 0 || window.orientation == 180 ) { 
        alert ('Please use your mobile device in landscape mode'); 
    }
};
sfletche
  • 47,248
  • 30
  • 103
  • 119
Allan Moody
  • 31
  • 1
  • 1
  • 5
1

You can make the website alert users who are using a mobile device, not just when the device is in landscape.

This question will probably help you out.


Or, the answer to your exact question might be on this duplicate question.


You may also try identifying the the user with

var isiPad = navigator.userAgent.match(/iPad/i) != null;

And sending him an alert if this does not equal NULL

I hope this helped you out.

Community
  • 1
  • 1
HelpingHand
  • 1,045
  • 11
  • 26
  • Instead I used the following code `window.onload=function(){if ( window.orientation == 0 || window.orientation == 180 ){ alert ('Please use your iPad in landscape mode'); }}` – Allan Moody May 20 '13 at 16:56
  • Okay, if that method worked then post it as an answer. Congratulations. Have a good day. – HelpingHand May 20 '13 at 17:38