Random display of pictures or banner

Source: Internet
Author: User
Tags domain name
Random | Show if you need to randomly display pictures or link banner on your home page, how do you do that? We introduce the use of JavaScript to achieve this effect!

Here is a random display of five banner code, you can define your own.
<script language=javascript>
<!--
var b_num =12
var b=new Array ();

function Init_item () {
This.width = ' '
This.height = ' '
THIS.SRC = ' '
This.href = ' '
This.border = ' '
This.alt = ' '
This.under = ' '
This.grade=0
This.target= '
}

function Createarray (BA, Itemnum) {
for (var i=0 i<itemnum; i++) {Ba[i] = new Init_item ()}
}

function Requestbanner (BA) {
sum=0;
for (i=0;i<ba.length;i++) Sum+=ba[i].grade
var slump = Math.random ();
var talet = Math.Round (slump* (sum-1)) +1;
i=0;
sum=0;
while (I<ba.length && sum<=talet) {sum+=ba[i].grade;i++;}
B=BA[I-1];
Visa = ';
if (b.target!= ') {
Visa + = ' <a href= ' +b.href+ ' target= ' +b.target+ ' > ';
else{
Visa = ' <a href= ' +b.href+ ' > ';
}
Visa = ' Visa = ' width= ' +b.width+ ' border= ' +b.border+ ' alt= ' +b.alt+ ' > ';
Visa = ' </a> ';
document.write (Visa);
}

Createarray (B,b_num)

B
B[0].SRC = "Http://www.webjx.com/images/468_60.gif"
Banner Picture Path
B[0].href = "Http://www.webjx.com"
Banner Link Address
b[0].target= "_blank"
B[0].width = "468"
B[0].height = "60"
B[0].border = "0"
B[0].alt = ":::: Web Teaching Network::::"
Banner Text hints
B[0].under = ' '
B[0].grade = 20

B
B[2].SRC = "Http://www.webjx.com/ads/sucai114.gif"
B[2].href = "Http://www.webjx.net"
b[2].target= "_blank"
B[2].width = "468"
B[2].height = "60"
B[2].border = "0"
B[2].alt = ":::: Alternate domain name::::"
B[2].under = ' '
B[2].grade = 20

B
B[3].SRC = "Http://www.webjx.com/ads/banner.gif"
B[3].href = "Http://bbs.webjx.com"
b[3].target= "_blank"
B[3].width = "468"
B[3].height = "60"
B[3].border = "0"
B[3].alt = ":::: Technical Forum::::"
B[3].under = ' '
B[3].grade = 20

Requestbanner (b);
-->
</Script>
Insert this JS code into the <body> corresponding position.
Users can modify the relevant code, or increase, reduce the number of banner.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.