How to limit the number of iterations done by setInterval

前端 未结 5 2229
别那么骄傲
别那么骄傲 2021-01-04 05:34

I display video ads to my users. I don\'t host these ads by the way; I get them from another company.

When ever an ad is clicked it leaves a cookie in the user\'s b

5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-04 06:20

    This should do it:

    function checkCookie() {
        var cookie = getCookie("PBCBD2A0PBP3D31B");
        if (cookie != null && cookie != "") {
            alert("You clicked on an ad");
        }
        if (counter > 10) clearInterval(clr);
        counter++;
        clr = setInterval(function(){checkCookie()}, 10000);​
    }
    var counter = 0;
    checkCookie();
    

提交回复
热议问题