
When I step through this code, the values pictured result in cssLoaded = 0; From what I can see, the length is greater than 0 and cssStylesheet.sheet has properties so should be true, therefore cssLoaded should be set to 1, however it’s not happening. I must be missing something here..?
function _cssIsLoaded(cssStylesheet, stylePath) {
var cssLoaded = 0;
if (tryCount == 3){
console.log('oops');
}
if (cssStylesheet.href == stylePath){
try {
if ( cssStylesheet.sheet && cssStylesheet.sheet.cssRules.length > 0 ){
cssLoaded = 1;}
else if ( cssStylesheet.styleSheet && cssStylesheet.styleSheet.cssText.length > 0 ){
cssLoaded = 1;}
else if ( cssStylesheet.innerHTML && cssStylesheet.innerHTML.length > 0 ){
cssLoaded = 1;}
}
catch(ex){ }
}
if(cssLoaded) {
//alert('cssloadedcomplete');
resetPops();
$('#video-overlay').show();
positionElements();
saveBizzmail();
console.log('try:' + tryCount)
} else {
tryCount+=1;
console.log('try:' + tryCount);
setTimeout(function() { this._cssIsLoaded(cssStylesheet); }, 2000);
}
}
There are three possible ways your code gets cssLoaded == 0;
if (cssStylesheet.href == stylePath)evaluates tofalse.if/elsestatements evaluate tofalse.if/elsestatements throws an exception and thus the otherif/elsestatements aren’t executed.In troubleshooting your issue, you should verify that the first two are not the issue as those are probably just logic errors in the comparisons or the data coming into the function isn’t what you expected it to be.
For the third issue, you can implement defensive coding to make sure that all three
if/elsestatements are checked by changing your code to this (you don’t even need the try/catch any more because it allows your code to bypass some of the tests):