Hi, I am having issues with the following code:
var seachHttp = function () {
var cssSheets = document.styleSheets, // Loaded CSS Sheets
i =0, il = cssSheets.length, // Counter and limit for sheets
j, jl, rules, rule, // Counter and vars for Rules inside a Sheet
stylesToSearch = [ // Properties to Seach HTTP ON
'background',
'background-image',
],
k, kl=stylesToSearch.length, // Counter for properties
srule, // Current Property
vrule; // Current Value
for(;i<il;i++) { // Loop Sheets
rules = cssSheets[i].rules || cssSheets[i].cssRules;
for(j=0,jl=rules.length;j<jl;j++) { // Loop Rules
rule = rules[j];
for(k=0;k<kl;k++){ // Loop Styles
srule = stylesToSearch[k];
//alert(srule);
vrule = rule.style[srule];
//alert(vrule);
if (vrule === undefined || vrule === null) {
return;
} else {
if (vrule !== undefined && vrule.toString().toLowerCase().indexOf("http") > -1 ) { // Seach for HTTP Content
//alert("Found HTTP at " + rule.selectorText + " " + srule + " = " + rule.style[srule]);
return true;
}
}
}
}
}
return false;
}
Basically this script shows a notification if CSS contains HTTP content.
Every now and again when the script returns "undefined" the script stops and goes no futher. However, what I don't understand is I have conditions in place for this result as you can see in the code above.
I check the final result value using:
var cssresult = seachHttp();
if (div_array.length > 0 || cssresult === true) {
// do this
}
So just to recap, the only issue I have is if "vrule = rule.style[srule];" is undefined.