Basically what I'm trying to do is get my viewport width the same on all mobile browsers and make sure the user cannot zoom in or out (scale).
The mobile browsers that don't seem to support this correctly are:
- Windows phone 8 IE10
- Android native browser
- Android Firefox browser
The following line of code works on all mobile browsers except the one from the company that rejects standards as usual (IE, in this case IE10 Mobile):
<meta name="viewport" content="width=620, user-scalable=no" />
I found this question with accepted answer:
Viewport for IE10 & 11 desktop, but not mobile
After applying the below css and javascript code, it still keeps the viewport as device-width instead of the 620 I'm trying to achieve.
CSS:
@-webkit-viewport { width: 620; }
@-moz-viewport { width: 620; }
@-ms-viewport { width: 620; }
@-o-viewport { width: 620; }
@viewport { width: 620; }
Javascript:
$(function(){
if (navigator.userAgent.match(/IEMobile\/10\.0/) || navigator.userAgent.match(/IEMobile\/11\.0/)) {
var msViewportStyle = document.createElement("style")
msViewportStyle.appendChild(
document.createTextNode(
"@-ms-viewport{width:auto!important}"
)
)
document.getElementsByTagName("head")[0].appendChild(msViewportStyle)
}
alert($(window).width());
});