Hello, Have 2 or more javascript banner ads from different ad networks. How to make these banners to rotate on each page refresh? I would appreciate if anyone who knows, is willing to share the knowledge
I'm assuming you mean that you load the ads from one ad network on load 1, and then the other network on refresh, and so on and so forth? Just do it in the backend, and load the different javascript code on each page-load?
Yes, that is what i mean. Each page refresh to load different javascript code.. and to be a loop. never stop loading the scripts.
Why are you using javascript over PHP? What is the platform your site is running on? A CMS, like wordpress, or basic HTML?
Then you code it in the backend - fairly easy to do, and you could incorporate any number of ad networks. You could even make it so that it never loads the same network twice in a row (true random would make the same networks sometimes load again), and so forth. Why use javascript for this?
Because my CMS doesn't allow using php in the template. If it doesn't take you much time, could please explain how to do this in both javascript and php?
So your problem is determining when to load the ads 1, when to load the ads 2, right? You can do this in JavaScript by using localStorage function onload() { var lastAds = localStorage.getItem("lastAdsKey") || 1; if (lastAds == 1) { lastAds = 2; //TODO: load ads 2 } else { lastAds = 1; //TODO: oad ads 1 } localStorage.setItem("lastAdsKey", lastAds); } Code (JavaScript):