Fix IE 10 on Windows Phone 8 Viewport

Avatar of Chris Coyier
Chris Coyier on
(function() {
  if (navigator.userAgent.match(/IEMobile\/10\.0/)) {
    var msViewportStyle = document.createElement("style");

Quick backstory

For IE 10 (desktop) to work in it’s new “snap mode” you need to use this:

@-ms-viewport {
  width: device-width;

But that screws up some Windows Phone 8 phones, overriding the meta viewport tag and rendering as far too large on small screens. So the answer, for now, is this gnarly device detection/injection script.

Longer backstory