修复 Windows Phone 8 上的 IE 10 视口

Avatar of Chris Coyier
Chris Coyier
(function() {
  if (navigator.userAgent.match(/IEMobile\/10\.0/)) {
    var msViewportStyle = document.createElement("style");
    msViewportStyle.appendChild(
      document.createTextNode("@-ms-viewport{width:auto!important}")
    );
    document.getElementsByTagName("head")[0].appendChild(msViewportStyle);
  }
})();

简要背景

为了让 IE 10(桌面版)在其新的“贴靠模式”下工作,您需要使用以下内容

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

但这会搞砸一些 Windows Phone 8 手机,覆盖元视口标签,并在小屏幕上呈现得过大。所以目前的解决办法是使用这个棘手的设备检测/注入脚本。

更详细的背景