Prevent scrolling on mobile devices

If you don’t want that the user can scroll your website (to disable the bump-effect on iPhones and iPads for example), then you can use this code snippet which prevents the scrolling on mobile/touch devices:

<script type="text/javascript">
function preventDefaultScrolling(event){
document.ontouchstart = document.ontouchmove = document.ontouchend = preventDefaultScrolling;

For re-enabling the default scrolling behavior you can do the following:

<script type="text/javascript">
function restoreDefaultScrolling(event){
  return true;
document.ontouchstart = document.ontouchmove = document.ontouchend = restoreDefaultScrolling;

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.