Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use JavaScript to set the zoom level on mobile safari?

How can I use JavaScript to set the zoom level on mobile safari?

like image 646
Drew LeSueur Avatar asked Dec 21 '10 17:12

Drew LeSueur


People also ask

How do I change the zoom on Safari Mobile?

Adjust the magnification: Double-tap the screen with three fingers (without lifting your fingers after the second tap), then drag up or down. Or triple-tap with three fingers, then drag the Zoom Level slider.

How do I change the zoom percentage in Safari on my iPhone?

Open the Settings app , then scroll down and tap Safari. Scroll down and tap Page Zoom. Tap which percentage you would like the default zoom level to be for all websites.


1 Answers

[UPDATED] It seems that you want to capture double taps in mobile Safari. You could do that by handling the touchend event, or use an available framework, such as provided in this site.

Take a look at the revised demo: http://jsbin.com/atayo4/20

  <p id="tap">double tap to zoom</p>
  <input id="zoomWidth" type="text" value="400" />
  <p id="feedback"></p>

$(document).ready(function(){
  $('#tap').doubletap(
    // double tap handler
    function(e) {
      $('#feedback').addClass('red').html('double tap! Zoom width: ' + $('#zoomWidth').val());

      var zoomWidth = $('#zoomWidth').val();

      // zoom with the new width
      $('meta[name="viewport"]').attr('content', 'width=' + zoomWidth + ', user-scalable:no');

      $('#zoomWidth').val(parseInt(zoomWidth, 10) - 25);
    },

    // single tap handler
    function(e) {
      $('#feedback').removeClass('red').html('single tap! Zoom width: ' + $('#zoomWidth').val());
    },

    // double tap delay, default 500
    400
    );
});
like image 79
William Niu Avatar answered Oct 03 '22 14:10

William Niu