crazyyy
11/16/2016 - 5:08 PM

width of screen on mobile

width of screen on mobile

function mobileFriendly() {
  setTimeout(function() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)) {
      var ww = (document.documentElement.clientWidth < window.screen.width) ? jQuery(window).width() : window.screen.width; //get proper width
      var mw = 725;
      //alert ("width" + ww);
      var ratio = ww / mw; //calculate ratio
      //alert ("ratio: " + ratio);
      if (ratio < 1) { //smaller than minimum size
        jQuery("meta[name='viewport']").attr('content', 'initial-scale=' + ratio + ', maximum-scale=' + ratio + ', minimum-scale=' + ratio + ', user-scalable=yes, width=' + mw);
      } else { //regular size
        jQuery("meta[name='viewport']").attr('content', 'initial-scale=1.0, maximum-scale=2, minimum-scale=1.0, user-scalable=yes, width=' + ww);
      }
    }
  }, 600);
}
jQuery(document).ready(function() {
  mobileFriendly()
});
window.addEventListener("orientationchange", mobileFriendly, false);
<meta content="user-scalable=yes, maximum-scale=1.6, width=device-width, initial-scale=1, target-densitydpi=device-dpi" name="viewport">