JavaScript Finding background color of page or page view using Javascript

You can use the pure javascript or jquery to achieve what you want. To do what you want you can use this functions

Find by tagname:

function getBackgroundByTagName(tag){
    var color =  $(tag).css('background-color');
    console.log(color);
}

Find by class:

function getBackgroundByClassName(classname){
    var color =  $('.'+classname).css('background-color');
    console.log(color);
}

Find by id

function getBackgroundById(idofelement){
    var color =  $('.'+idofelement).css('background-color');
    console.log(color);
}

All you need to do is to run any of the functions and it will show the color in console.

Answer:1

Here's a start. This will get the background-colour of the <body> tag, whether it's inline or in an external stylesheet.

function getBackground() {

    var getBody = document.getElementsByTagName("body")[0]
    var prop = window.getComputedStyle(getBody).getPropertyValue("background-color");

    if (prop === "transparent") {
        console.log("No background colour set")
    } else {
        console.log(prop);
    }
}

getBackground();

JSFiddle Demo

Answer:2

In theory you could use a canvas element to draw the web page into it and then examine a particular pixel to see what colour it was:

  1. Get all the DOM elements and draw then to a canvas: Mozilla - Drawing_DOM_objects_into_a_canvas

Using script you'd need to clone the contents of the page in question, and then paste it into a canvas element.

  1. Get the pixel colour: Stack Overflow - get-pixel-color-from-canvas-on-mouseover

You could choose the coordinates with the mouse pointer, or you could simple hard code a specific pixel (in the corner of the page perhaps).

Answer:3

My website uses hashchange-triggered AJAX (to make it more bookmark-friendly). The problem I am having is that when I click "submit" in a form, all the form data that is serialize()'d to be sent via $....

My website uses hashchange-triggered AJAX (to make it more bookmark-friendly). The problem I am having is that when I click "submit" in a form, all the form data that is serialize()'d to be sent via $....

  1. whataburger
  2. whatsapp
  3. what time is it
  4. what is a bear market
  5. what is my ip
  6. what song is this
  7. what is a dry cough
  8. what stocks to buy today
  9. what to watch
  10. whataburger menu
  11. what is the weather
  12. what is rsv
  13. what to buy for flu pandemic
  14. what does ���� mean
  15. what is gluten
  16. what is pv
  17. what is a boomer
  18. what we do in the shadows
  19. what is lupus
  20. what is socialism

In the example below, map is called twice per onNext call which is unnecessary, because the same value for ds can be reused for the two observers. How to write the code such that the map is only ...

In the example below, map is called twice per onNext call which is unnecessary, because the same value for ds can be reused for the two observers. How to write the code such that the map is only ...

I am not able to set maximum height on the slider I am using, every height I set doesn't seem to be working. I have also tried setting the width on echo img row on the php part but it is not working. ...

I am not able to set maximum height on the slider I am using, every height I set doesn't seem to be working. I have also tried setting the width on echo img row on the php part but it is not working. ...

  1. setting height 100 not working
  2. setting div height not working
  3. jquery setting height not working

I have a lot of problems in my code because it is not synchronous. Here is an example of problem that i have in a chrome extension. This is my function function getTranslation(a_data, callback) { ...

I have a lot of problems in my code because it is not synchronous. Here is an example of problem that i have in a chrome extension. This is my function function getTranslation(a_data, callback) { ...

  1. javascript synchronous functions
  2. js synchronous functions
  3. javascript synchronous callback
  4. javascript synchronous calls
  5. javascript synchronous method
  6. javascript synchronous method call
  7. js synchronous callback
  8. js synchronous method
  9. javascript callback synchronous or asynchronous
  10. node js synchronous functions
  11. javascript synchronous and asynchronous functions
  12. javascript make functions synchronous
  13. javascript synchronous vs asynchronous functions