trixter52
11/30/2017 - 7:42 AM

Change the viewport value based on screen.width

 // Store the meta element
  var viewport_meta = document.getElementById('viewport-meta');

  // Define our viewport meta values
  var viewports = {
      default: viewport_meta.getAttribute('content'),
      landscape: 'width=640'
    };

  // Change the viewport value based on screen.width
  var viewport_set = function() {
      if ( screen.width < 767 )
        viewport_meta.setAttribute( 'content', viewports.landscape );
      else
        viewport_meta.setAttribute( 'content', viewports.default );
    }

  // Set the correct viewport value on page load
  viewport_set();

  // Set the correct viewport after device orientation change or resize
  window.onresize = function() { 
    viewport_set(); 
  }