Random Image Banner & Link Script To Show Different Ads On Every Refresh - Cyber Tweaks

Ads Top

Random Image Banner & Link Script To Show Different Ads On Every Refresh

Html javascript Code to Show Random Advertisng Banner

If you have a website loaded with too many images banners that make your website load slow every time someone visits your site?

You may need to change it with this javascript which displays random images to users whenever someone opens a new page or refresh it.

This is a simple code, you just need to place it wherever you want to display advertisement, whether on the slider, header, footer, or within the article.

You can customize the script your own way by putting your own images, link, alt image details to make it more SEO Friendly.

So, here is the script you can put anywhere you want to display random ads on your websites visitors


<script type="text/javascript">
var images = [],
index = 0;

images[0] = '<a href = "Your Link" rel="nofollow noopener" target="_blank"><img src="Your Image" alt="alt text"></img></a>';
images[1] = '<a href = "Your Link" rel="nofollow noopener" target="_blank"><img src="Your Image" alt="alt text"></img></a>';
images[2] = '<a href = "Your Link" rel="nofollow noopener" target="_blank"><img src="Your Image" alt="alt text"></img></a>';
images[3] = '<a href = "Your Link" rel="nofollow noopener" target="_blank"><img src="Your Image" alt="alt text"></img></a>';
images[4] = '<a href = "Your Link" rel="nofollow noopener" target="_blank"><img src="Your Image" alt="alt text"></img></a>';
images[5] = '<a href = "Your Link" rel="nofollow noopener" target="_blank"><img src="Your Image" alt="alt text"></img></a>';


index = Math.floor(Math.random() * images.length);
document.write(images[index]);
</script>

Things you need to edit with your details

  1. <a href = "Your Link" rel="nofollow noopener" target="_blank"> : Put your Link here
  2. <img src="Your Image" alt="alt text"></img> : Insert Your Image Link and Alt Text

This demo script displays up to 6 images. if you want to add more simply copy this code and add images numbers


images[6] = '<a href = "Your Link" rel="nofollow noopener" target="_blank"><img src="Your Image" alt="alt text"></img></a>';

Change images[6] number everytime you want to add new image.

No comments:

Powered by Blogger.