Advertisement
mindfriction

IE Mobile viewport fix

May 8th, 2014
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 1.06 KB | None | 0 0
  1. /*
  2. Internet Explorer 10 doesn't differentiate device width from viewport width, and thus doesn't properly apply the media queries in Bootstrap's CSS. Normally you'd just add a quick snippet of CSS to fix this: @-ms-viewport       { width: device-width; }
  3.  
  4. However, this doesn't work for devices running Windows Phone 8 versions older than Update 3 (a.k.a. GDR3), as it causes such devices to show a mostly desktop view instead of narrow "phone" view. To address this, you'll need to include the following CSS and JavaScript to work around the bug.
  5. */
  6.  
  7.  
  8. @-webkit-viewport   { width: device-width; }
  9. @-moz-viewport      { width: device-width; }
  10. @-ms-viewport       { width: device-width; }
  11. @-o-viewport        { width: device-width; }
  12. @viewport           { width: device-width; }
  13.  
  14.  
  15. if (navigator.userAgent.match(/IEMobile\/10\.0/)) {
  16.   var msViewportStyle = document.createElement('style')
  17.   msViewportStyle.appendChild(
  18.     document.createTextNode(
  19.       '@-ms-viewport{width:auto!important}'
  20.     )
  21.   )
  22.   document.querySelector('head').appendChild(msViewportStyle)
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement