I seem unable to get the data I want, at least on FireFox, where I'm
currently testing the script. This is the code that I currently have
(it runs onload):
var styleSheets = document.styleSheets;
var stringOfAllStyleRules = "";
for (var i=0; i < styleSheets.length; i++) {
var thisStyleSheet = styleSheets;
if (thisStyleSheet.cssRules) {
var listOfStyleSheetRules = thisStyleSheet.cssRules;
}
if (thisStyleSheet.rules) {
var listOfStyleSheetRules = thisStyleSheet.rules;
}
if (typeof listOfStyleSheetRules == "undefined") {
window.status = "No style rules could be found";
} else {
for (var r=0; r < listOfStyleSheetRules.length; r++) {
var thisRule = listOfStyleSheetRules[r];
if (typeof thisRule["style"] != "undefined") {
var styleObject = thisRule["style"];
var backgroundImageUrl = styleObject["backgroundImage"];
if (backgroundImageUrl != "") {
stringOfAllStyleRules += backgroundImageUrl;
stringOfAllStyleRules += "<br /> \n";
}
}
}
}
}
if (stringOfAllStyleRules) document.getElementById("recently-viewed-
items").innerHTML = stringOfAllStyleRules;
That final line, where I write the data to recently-viewed-items, is
just so that I can see what is going on. Once I've got the images that
I want, I'll do something more interesting.
However, I'm not getting the URLs that I want. This is all I get:
url(Simplicity%20Home/bg-body.jpg)
none
none
none
none
url(../img/icon-envelope-on.gif)
url(../img/icon-envelope.gif)
url(../img/icon-mobile-on.gif)
url(../img/icon-mobile.gif)
Meanwhile, the style sheets have rules such as this:
li#patterns em, li#apparel em, li#tapes em, li#appliques em,
li#closures em, li#mend em, li#decor em, li#sewing em, li#quilting em,
li#ribbon em, li#crochet em, li#kits em, li#products em{
background: url(Simplicity Home/bg-nav.png) no-repeat;
cursor: pointer;
}
/*Patterns*/
body.patterns li#patterns em{
background: url(Simplicity Home/bg-nav-patterns.png) no-repeat;
}
body.patterns li#patterns:hover em{
background: url(Simplicity Home/bg-nav-patterns.png) no-repeat;
background-position: 0 -46px;
}
None of those background images are being discovered by my script.
What am I doing wrong?