Created
August 19, 2012 17:13
-
-
Save joesteinkamp/3396385 to your computer and use it in GitHub Desktop.
Load Embedded CSS Styles Based on User Agent
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
// Add Style Tag to Head | |
var head = document.getElementsByTagName('head')[0]; | |
var style = document.createElement('style'); | |
style.id = 'newStyle'; | |
head.appendChild(style); | |
var styles; | |
// Check if iPhone or iPod | |
if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) { | |
styles = 'body { background: #0ff; }'; | |
} | |
// Check if Android | |
if ((navigator.userAgent.match(/Android/i))) { | |
styles = 'body { background: #ff0; }'; | |
} | |
// Load styles | |
document.getElementById("newStyle").innerHTML = styles; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment