Skip to content

Instantly share code, notes, and snippets.

@brandonpapworth
Created May 7, 2013 23:43
Show Gist options
  • Save brandonpapworth/5537102 to your computer and use it in GitHub Desktop.
Save brandonpapworth/5537102 to your computer and use it in GitHub Desktop.
Adapted from http://mattstow.com/responsive-design-in-ie10-on-windows-phone-8.html , This will append a style tag to the document head containing the @Viewport rule necessary for windows * 8 systems to properly read. Since Windows Phone 8 doesn't react as it should to width=device-width rules, it's necessary to have it defined with a width of 'a…
<script>
/*
* IE10 viewport handler for use on mobile devices and snapped desktop
*/
(function(document,navigator) {
'use strict';
var msViewportStyleShim = document.createElement('style');
msViewportStyleShim.appendChild(
document.createTextNode(
'@-ms-viewport{width:' + (
'-ms-user-select' in document.documentElement.style && navigator.userAgent.match(/IEMobile\/10\.0/)
? 'auto!important'
: 'device-width'
) + ';}'
)
);
document.getElementsByTagName('head')[0].appendChild(msViewportStyleShim);
})(document,navigator);
</script>
<!-- minified below
<script>(function(a,b){var c=a.createElement("style");c.appendChild(a.createTextNode("@-ms-viewport{width:"+("-ms-user-select" in a.documentElement.style&&b.userAgent.match(/IEMobile\/10\.0/)?"auto!important":"device-width")+";}"));a.getElementsByTagName("head")[0].appendChild(c)})(document,navigator);</script>
-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment