What\'s the best way to find all of the background images on a given page using javascript?
The ideal end result would be an array of all of the url\'s.
Without using jQuery, you can do:
var elementNames = ["div", "body", "td"] // Put all the tags you want bg images for here
var allBackgroundURLs = new Array();
elementNames.forEach( function(tagName) {
var tags = document.getElementsByTagName(tagName);
var numTags = tags.length;
for (var i = 0; i < numTags; i++) {
tag = tags[i];
if (tag.style.background.match("url")) {
var bg = tag.style.background;
allBackgroundURLs.push(bg.substr(bg.indexOf("url") + 4, bg.lastIndexOf(")") - (bg.indexOf("url") + 4) ) );
}
}
});