Вот способ проверить, какие фоновые URL-адреса присутствуют в стилях на странице (смотрите Ма, нет jQuery):
window.npup = (function (doc) {
var sheets = doc.styleSheets;
var hash = {}, sheet, rules, rule, url, match;
// loop the stylesheets
for (var sheetIdx=0, sheetsLen=sheets.length; sheetIdx<sheetsLen; ++sheetIdx) {
sheet = sheets[sheetIdx];
// ie or w3c stylee rules property?
rules = sheet.rules ? sheet.rules : sheet.cssRules;
// loop the rules
for (var ruleIdx=0, rulesLen=rules.length; ruleIdx<rulesLen; ++ruleIdx) {
rule = rules[ruleIdx];
if (rule.selectorText && rule.style.cssText) {
// check if there's a style setting we're interested in..
if (rule.style.cssText.match(/background/)) {
// ..and if it has an url in it, put it in the hash
match = /url\(([^)]*)\)/.exec(rule.style.cssText);
if (match) {hash[match[1]] = true;}
}
}
}
}
// return an array of unique urls
var urls = [];
for (url in hash) {urls.push(url);}
// export a getter for what we found
return {
getBackgroundUrls: function () { return urls;}
};
})(document); // submit reference to the document of interest
С этим на странице вы можете получить массив URL с npup.getBackgroundUrls();
Я сделал несколько (лишних?) Комментариев в коде, которые объясняют, как это происходит.
Это не захватывает встроенные стили, но я думаю, что это не проблема для вас?
Стили на внешних листах и в тегах <style>
на странице очищаются .
Процедуру легко изменить, если вы хотите вести подсчет или поддерживать ассоциации с фактическими правилами, в которых был найден URL-адрес и т. Д.