Search code examples
javascriptcssgoogle-chrome-extensionwindowbackground-color

Get and Use Background Color to apply the same color in other window


I am doing a Chrome Extension and I need to get the background color of the current page and change the background color of a window to the color obtained previously, how can I do that in javascript ( with or without jQuery ) and if necessary html or css?


Solution

  • You can use DOMObject.style.backgroundColor and window.getComputedStyle:

    <object to set background color of>.style.backgroundColor = window.getComputedStyle(document.getElementsByTagName(“BODY”)[0], null).getPropertyValue("background-color")
    

    You can find documentation here:

    https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style

    https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle