0

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.

2
Contributors
1
Reply
39
Views
2 Years
Discussion Span
Last Post by bigtalk
0

On line 24, if vrule is undefined or null, you return ending the script. In the script where you call seachHttp(), cssresult will, in that instance, not be set with a boolean. Perhaps you would rather have line 24 continue instead. That way, you would finish the for loop and then potentially find http content or ultimately return the default false.
Additionally, you check if div_array has a length greater than 0. What happens if the length is 0 and cssresult is NOT true?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.