Linked Questions

Popular Questions

I have a webpage which have a "viewport" tag with the following value:

<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />  

I want to allow zooming on that page which is displayed in a WebView so I inject some javascript on onPageFinished() as follow:

webView.loadUrl("javascript:document.getElementsByName('viewport')[0].setAttribute('content', 'width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=yes');");

but it doesn't work. * I also tried rearranging properties like this

webView.loadUrl("javascript:document.getElementsByName('viewport')[0].setAttribute('content', 'user-scalable=yes, width=device-width, minimum-scale=1.0, maximum-scale=1.0');");

or removing the property like this

webView.loadUrl("javascript:document.getElementsByName('viewport')[0].setAttribute('content', 'width=device-width, minimum-scale=1.0, maximum-scale=1.0');");

with the same result.

  • after some trials I found out that I can override maximum-scale only if there was no "user-scalable=no" defined at all in the page. for example if the Viewport metadata was like this:

    <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0" />
    

everything would work just fine.

  • I checked the value of the "viewport" tag after injection using javascript:alert(...), and it was modified by the injection, yet with no actual result.

  • I tried setting UseWideViewPort with true or false, and it didn't help neither:

    webView.getSettings().setUseWideViewPort(true);
    //or
    webView.getSettings().setUseWideViewPort(true);
    

    the samething with setLoadWithOverviewMode()

  • zooming doesn't work even programmatically using zoomIn() or zoomOut().

  • I've tested using android 2.3 and android 4.4.2 with the same results.

  • note: I did read almost all the questions on this site related to zooming and viewport, but nothing was useful in my case.

  • my webView settings are defined as follow:

    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setSupportZoom(true);
    webView.getSettings().setBuiltInZoomControls(true);
    
  • So is there any other ways to allow zooming and override the metadata?

  • a solution which is compatible with API 10 would be very appreciated.

Related Questions