Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 73935

javascript banners freezes on first banner

$
0
0

I have two banners which I added recently to my website and I'd like to change the banners every 5 seconds, unfortunately, it shows only the first one and freezes

<script>
    var links = ["http://site","http://site"];
    var images = ["/uploads/ad1.png","/uploads/ad2.png"];
    var i = 0;
    var renew = setInterval(function(){
        if(links.length == i){
            i = 0;
        }
        else {
            document.getElementById("bannerImage").src = images[i];
            document.getElementById("bannerLink").href = links[i];
            i++;

        }
    },500);
</script>
<div class="container"><div class="text-center"><a id="bannerLink" href="http://site" onclick="void window.open(this.href); return false;"><img id="bannerImage" src="/uploads/ad1.png" width="320" height="120" alt="some text"></a></div></div>

Viewing all articles
Browse latest Browse all 73935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>