So I have three functions here, they're messing about with each other.

  • The first function loads a URL in an element with a fancy effect
  • The second function checks an element for adblock
  • Finally the third function updates the first function URL every 30 seconds

Take a look:

$(document).ready(function() {

var update = function(element, url) {
    if ($(element).length) {
        $(element).effect("highlight", {color: "#f7f7f7"}, 2000); $(element).load(url);
   }
}

var adblock = function(adspace) {
    if ($(adspace).height() == 0 || $(adspace).length() <= 1) {
        window.location.replace("../disable-adblock");
    }
}

adblock(".coinurl");       

var refresh_div = setInterval(function() {
    update(".total-plays", "../logs/total-plays.txt");
}, 30000);

$.ajaxSetup({ cache: false });

}); //doc

Now the problem is that for some reason the OR (||) operator in the second function disables my setInterval function. But, when I delete || $(adspace).length() <= 1 everything works fine - accept now the adblock function doesn't work with Chrome!

What's going on here? Have I executed the OR statement incorrectly, or is this script in the wrong order?

Thanks

有帮助吗?

解决方案

length is not a function, it is a property

var adblock = function(adspace) {
    if ($(adspace).length <= 1 || $(adspace).height() == 0) {
        window.location.replace("../disable-adblock");
    }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top