I am trying to make a javascript fragment that can get a list of all the images (or other resources) that are used on a web page because they are specified in css. These are usually background images, because somewhere in css there is something like this:
.something {
background: transparent url(images/somethingbg.png) no-repeat top left;
}
It seems I can get it all into an array (with a full path) with the following snippet:
var outputArray = [];
var string = "";
var elems = document.getElementsByTagName('*');
for (var i = 0; i<elems.length; i++) {
var elem = elems[i];
var style = window.getComputedStyle(elem, null);
var value = style.getPropertyValue("background-image");
if (value && value != "" && value != "none")
outputArray.push(value);
}
However, I want this to work on any file (works like a bookmarklet), and I know that url () can be applied to things that are not background images, such as "list-style-image". Is there any more? Is there a list somewhere?
source
share