Skip to content

Instantly share code, notes, and snippets.

@joesteinkamp
Created August 19, 2012 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joesteinkamp/3396385 to your computer and use it in GitHub Desktop.
Save joesteinkamp/3396385 to your computer and use it in GitHub Desktop.
Load Embedded CSS Styles Based on User Agent
// 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