Mobile Geräte erkennen mit JavaScript

Oftmals müssen Webseiten an ein spezifisches Endgerät angepasst werden. Dazu muss man wissen, mit welchem Gerät man es überhaupt zu tun hat. Dabei kann einem die Navigator userAgent Property behilflich sein.
Mobile Geräte erkennen mit JavaScript weiterlesen

How to get the iPad viewport size with jQuery

Detecting the viewport size of an Apple iPad is very easy with jQuery. You just have to use the following code example:

    <script src="./js/jquery.js"></script>
    <script type="text/javascript">
      var width = $(window).width(); 
      var height = $(window).height(); 
      var pre = document.createElement('pre');
      pre.textContent = 'Viewport: '+width+'x'+height+' pixels';

The viewport for an iPad in landscape mode (with address bar) is 1024×690 pixels.
The viewport for an iPad in portrait mode (with address bar) is 768×946 pixels.
The viewport for an iPad in portrait mode (with address bar and debug console) is 768×896 pixels.

If you want to hide the address bar in portrait mode then you have to add the website to your homescreen and their must be this meta tag in your website’s header:

<meta name="apple-mobile-web-app-capable" content="yes" />

The viewport for a fullscreen portrait mode is then 768×1004 pixels.
The resolutions are based on the following setting:

<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />

If you do not have this setting (or if you use different values for it), then the viewport will be lager or even smaller.