Skip to content

Instantly share code, notes, and snippets.

@cmargroff
Last active August 15, 2018 21:48
Show Gist options
  • Select an option

  • Save cmargroff/51c47d553040af8b21cb to your computer and use it in GitHub Desktop.

Select an option

Save cmargroff/51c47d553040af8b21cb to your computer and use it in GitHub Desktop.
Set window color for Chrome 39 Android 4.3+
(function(window, document){
if (typeof window.chrome != "undefined") {
document.themeColorMeta = document.createElement("meta");
document.themeColorMeta.name = "theme-color";
document.themeColorMeta.content = "transparent";
document.head.appendChild(document.themeColorMeta);
Object.defineProperty(window, "themeColor", {
get: function(){
return document.themeColorMeta.content;
},
set: function(color){
document.head.removeChild(document.themeColorMeta);
document.themeColorMeta.content = color;
document.head.appendChild(document.themeColorMeta);
}
});
};
}(window, document))
/* Usage
| window.themeColor = "#db5945";
| window.themeColor = "rgb(82, 171, 217)";
| window.themeColor = "rgba(82, 171, 217, 0.5)"; //this does the same thing, no alpha is calculated.
| console.log(window.themeColor);
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment