X
Publisher: Sigit purnomo kangsigit.com@gmail.com

Javascript + jQuery to Random Link

You can set up multiple links to be displayed alternately on every page of the website with an jQuery javascript this. To help make edits, please see this page.

The following codes are required

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
function randomAds(){
//Author : Sigit Purnomo
//URL : http://www.kangsigit.com
//Tutorial : http://www.kangsigit.com/2015/12/javascript-random-link.html
//ONE
var myRandom1=Math.round(Math.random()*2) //angka 2 disesuaikan dengan jumlah link
var aLink1=new Array()
aLink1[0]="halaman-1-1.html"
aLink1[1]="halaman-1-2.html"
aLink1[2]="halaman-1-3.html"
var aText1=new Array()
aText1[0]="TEXT ONE 1"
aText1[1]="TEXT TWO 1"
aText1[2]="TEXT THREE 1"
//TWO
var myRandom2=Math.round(Math.random()*3) //angka 3 disesuaikan dengan jumlah link
var aLink2=new Array()
aLink2[0]="halaman-2-1.html"
aLink2[1]="halaman-2-2.html"
aLink2[2]="halaman-2-3.html"
aLink2[3]="halaman-2-4.html"
var aText2=new Array()
aText2[0]="TEXT ONE 2"
aText2[1]="TEXT TWO 2"
aText2[2]="TEXT THREE 2"
aText2[3]="TEXT FOUR 2"
$("#tempat-link").html("<ol><li><a href='"+aLink1[myRandom1]+"'>"+aText1[myRandom1]+"</a></li><li><a href='"+aLink2[myRandom2]+"'>"+aText2[myRandom2]+"</a></li></ol>")
};
$(document).ready(function(){
$("#tempat-link").html(randomAds);
});
</script>

Advertisement


<div id="tempat-link"></div>



Advertisement

no image
Add Comments
0 Comments
Click Here to Add Comments

No Comment