Last active
August 15, 2018 21:48
-
-
Save cmargroff/51c47d553040af8b21cb to your computer and use it in GitHub Desktop.
Set window color for Chrome 39 Android 4.3+
This file contains hidden or 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
| (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