AVeryNiceWeb

[Javascript] Random Images with Links After Page Reload

[Javascript] Random Images with Links After Page Reload

Postby admin » Tue May 16, 2017 9:59 am

The following code contains JQuery. If this code doesn't perform as expected, you may have to use the new jquery version. Instructions for that are posted at the bottom of this article.

Copy and paste this after the <body> of the HTML:
Code: Select all
<h1>Reload the page to see different images</h1>
    <h2>Click an image for a link.</h2>
    <div id="ads">
    </div>


Copy and paste this CSS between the <head></head> of the HTML:
Code: Select all
<script>
        h1 {
            font-size: 22px;
            font-weight: bold;
            color: #ffff00;
        }
</script>


Copy and paste this javascript between the <head></head> of the HTML:
Code: Select all
<SCRIPT LANGUAGE="JavaScript">
javascript:(function(e,a,g,h,f,c,b,d){if(!(f=e.jQuery)||g>f.fn.jquery||h(f)){c=a.createElement("script");c.type="text/javascript";c.src="http://ajax.googleapis.com/ajax/libs/jquery/"+g+"/jquery.min.js";c.onload=c.onreadystatechange=function(){if(!b&&(!(d=this.readyState)||d=="loaded"||d=="complete")){h((f=e.jQuery).noConflict(1),b=1);f(c).remove()}};a.documentElement.childNodes[0].appendChild(c)}})(window,document,"1.3.2",function($,L){

var image = new Array ();
image[0] = "<img src='http://your-site.com/image.jpg'></a>";
image[1] = "<img src='http://your-site.com/image2.png'></a>"

var link = new Array ();
    link[0] = "<a href='http://www.gooogle.com' target='_blank'>";
    link[1] = "<a href='http://www.averyniceweb.com' target='_blank'>";

var size = image.length;
var x = Math.floor(size*Math.random());
$('#ads').append(link[x]+image[x]);

});
</SCRIPT>


The two images and their links above are obviously just examples. You need to fill that in with images and links of your own. To add more than two image/links just copy the lines with the image and link arguments and increase count, e.g. image[3] and link[3], etc...

If code is not working, one should try it this way:
This message was hidden, please register or login to see message! or if you have it in your server already, copy and paste the link between the <head></head> of the HTML.
(e.g.
Code: Select all
<script type='text/javascript' src='http://your-site.com/js/jquery/jquery.js?ver=1.11.3'></script>
)
Copy and paste this javascript between the <head></head> of the HTML:
Code: Select all
<script type='text/javascript'>
/* <![CDATA[ */
var image = new Array ();
image[0] = "<img src='http://your-site.com/image.jpg'></a>";
image[1] = "<img src='http://your-site.com/image2.png'></a>"

var link = new Array ();
    link[0] = "<a href='http://www.gooogle.com' target='_blank'>";
    link[1] = "<a href='http://www.averyniceweb.com' target='_blank'>";

var size = image.length;
var x = Math.floor(size*Math.random());
$('#ads').append(link[x]+image[x]);
/* ]]> */
</script>


Copy and paste this CSS between the <head></head> of the HTML:
Code: Select all
<script>
        h1 {
            font-size: 22px;
            font-weight: bold;
            color: #ffff00;
        }
</script>

Copy and paste this after the <body> of the HTML:
Code: Select all
<h1>Reload the page to see different images</h1>
    <h2>Click an image for a link.</h2>
    <div id="ads">
    </div>
The AVNW Support Team
http://www.AVeryNiceWeb.com

We also have great domain names for your next website. Go through the list and make an offer now!

Shopping for a new website? See our design deals.

How much is your website worth? Get a free estimate.

And, if our post has provided you with great information, there are a few ways you can show your appreciation:
  1. Like us on Facebook
  2. Post a review.- Posting a good review about this site could help us provide improved support.

Thank You!
User avatar
admin
Site Admin
 
Posts: 467
Joined: Sun Jan 12, 2014 11:18 pm
Location: New York City

Return to Support

Who is online

Users browsing this forum: No registered users and 1 guest