Last active
March 11, 2016 11:14
-
-
Save haocong/6a2402a043e6ac35727c to your computer and use it in GitHub Desktop.
Set document meta on retina display
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var docEl = document.documentElement; | |
var metaEl = document.createElement('meta'); | |
var scale = devicePixelRatio > 1 ? 0.5 : 1; | |
metaEl.setAttribute('name', 'viewport'); | |
metaEl.setAttribute('content', 'initial-scale=' + scale + ', maximum-scale=' + scale + ', minimum-scale=' + scale + ', user-scalable=no'); | |
if (docEl.firstElementChild) { | |
docEl.firstElementChild.appendChild(metaEl); | |
} else { | |
var wrap = document.createElement('div'); | |
wrap.appendChild(metaEl); | |
document.write(wrap.innerHTML); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment