title: Javascript solution to detect ipad, and orientation
body: <p>Is there a reliable way to detect that a web-page is being viewed from an iPad (no false positives) and what the orientation is via JavaScript?</p>
  
  <p>I think this is good for the first part:</p>
  
  <pre><code>var isiPad = navigator.userAgent.match(/iPad/i) != null;
  </code></pre>
  
  <p>I think I have found the second part:</p>
  
  <pre><code>&lt;button onclick="detectIPadOrientation();"&gt;What's my Orientation?&lt;/button&gt;
  
  &lt;script type="text/javascript"&gt;
      window.onorientationchange = detectIPadOrientation;
      function detectIPadOrientation () {
          if ( orientation == 0 ) {
              alert ('Portrait Mode, Home Button bottom');
          } else if ( orientation == 90 ) {
              alert ('Landscape Mode, Home Button right');
          } else if ( orientation == -90 ) {
              alert ('Landscape Mode, Home Button left');
          } else if ( orientation == 180 ) {
              alert ('Portrait Mode, Home Button top');
          }
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>I don't know if it reliable for all iPads, including the new smaller one for example. So my question is: Would these functions work reliably on all iPads? And would there be any false positives?</p>