2

I made an app with phonegap. I didnt wantet to use media queries because so i had to change all parameters for diffrent viewport sizes. My idea was that i only change the inital scale of the html document with javascript. I know that i can change the initial scale with an function like i show here:

 if (document.documentElement.clientWidth < 480) {
        document
            .querySelector("meta[name=viewport]")
            .setAttribute('content', 'initial-scale=0.4', 'maximum-scale=0.4', 'width=768');
    };

but i want that the initial scale is at an width of 320 pixel of the viewport 0 or in other words 100%. And at a viewport width of 720 (Galaxy S3) 110% or in other words initial scale of 0.1. For all the viewport sizes that lay between javascript should calculate the scale. I have no idea how to achieve this! Im very happy about every help! Hope you unterstood me, im from germany!

Em Sta
  • 1,676
  • 9
  • 29
  • 43

1 Answers1

6

try this:

 if (document.documentElement.clientWidth < 480) { 
    document.querySelector("meta[name=viewport]").setAttribute(
          'content', 
          'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0');
 }

Reference : Can I change the viewport meta tag in mobile safari on the fly?

Tamil Selvan C
  • 19,913
  • 12
  • 49
  • 70
  • I wanted to add a missing curly brace but I can't because an edit has to be at least 6 characters :( – Gherman Apr 13 '18 at 15:17