Overriding the "user-scalable = no" Viewport metadata property in the webview to scale
I have a web page tagged "viewport" 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 this page which is displayed in the WebView so I am inserting some javascript on onPageFinished () like this:
webView.loadUrl("javascript:document.getElementsByName('viewport')[0].setAttribute('content', 'width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=yes');");
but that won't work. * I also tried to rebuild 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 by removing a 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 testing it turned out that I can only override the maximum scale if there was no "user-scalable = no" on 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 will work fine.
-
I checked the value of the "viewport" tag after the injection using javascript: alert (...) and it was modified by the injection but no actual result.
-
I tried setting UseWideViewPort to true or false and it didn't help either:
webView.getSettings().setUseWideViewPort(true); //or webView.getSettings().setUseWideViewPort(true);
samething with setLoadWithOverviewMode ()
-
scaling doesn't even work programmatically using zoomIn () or zoomOut ().
-
I tested with android 2.3 and android 4.4.2 with the same results.
-
note: I have read almost all of the zoom and view related questions on this site, but nothing was helpful in my case.
-
My webView settings are defined like this:
webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setSupportZoom(true); webView.getSettings().setBuiltInZoomControls(true);
-
So, are there any other ways to scale and override the metadata?
-
an API 10 compliant solution would be much appreciated.
source to share
No one has answered this question yet
Check out similar questions: