Home  >  Article  >  Web Front-end  >  The js pulled from NetEase calls the advertising display file (random probability)_advertising code

The js pulled from NetEase calls the advertising display file (random probability)_advertising code

WBOY
WBOYOriginal
2016-05-16 18:10:561341browse

The js pried from NetEase calls the ad display file
Only the following few lines of code can randomly display flash and gif ads, which is not bad

Copy code The code is as follows:

function column02(imgSource,url,chance,type) {
this.imgSource = imgSource;
this.url = url;
this.chance = chance;
this.type = type;
}
function dispColumn02() {
with (this)
switch (type){
case "img" :
document.write("");
break;
case "html":
document.write("");
break;
case "flash":
document.write("");
break;
default:
document.write("");
}
}
column02.prototype.dispColumn02 = dispColumn02;
columns02 = new Array();
// flash , html, img represent three different advertising modes
// Numbers such as 200 are to set the probability of occurrence
columns02[0] = new column02("http://smsimg.163.com/honey/honey_ad .swf","",200,"flash");//Main advertisement
columns02[1] = new column02("http://smsimg.163.com/honey/honey_photo.swf","", 800,"flash"); //Free monthly rent for uploading pictures
columns02[2] = new column02("http://smsimg.163.com/honey/honey_gold.swf","",800,"flash "); //Log in to get gold coins
//columns02[] = new column02("f","",100,"");// (20030422~20030722)
sum_of_all_chances = 0;
for (i = 0; i < columns02.length; i ) {
sum_of_all_chances = columns02[i].chance;
}
function randomColumn02() {
chance_limit = 0;
randomly_selected_chance = Math.round((sum_of_all_chances - 1) * Math.random()) 1;
for (i = 0; i < columns02.length; i ) {
chance_limit = columns02[i].chance ;
if (randomly_selected_chance <= chance_limit) {
columns02[i].dispColumn02();
break;
}
}
}
this_column02 = randomColumn02() ;

Script House test code, the greater the chance, the greater the chance of display

[Ctrl A select all Note: If you need to introduce external Js, you need to refresh to execute
]<script> function jb51(url,chance) { this.url=url; this.chance=chance; } var da,dalen,chance_limit,random_sel_num da=new Array(); da[0]=new jb51("http://www.baidu.com",200) da[1]=new jb51("http://www.jb51.net",600) da[2]=new jb51("http://sc.jb51.net",800) var dalen=da.length; num_all_chance=0; for(i=0;i<dalen;i++){ num_all_chance+=da[i].chance; } function random_da(){ chance_limit = 0; random_sel_num=Math.round((num_all_chance-1)*Math.random())+1; for(i=0;i<dalen;i++){ chance_limit+=da[i].chance; if(random_sel_num<=chance_limit){ alert(random_sel_num+"显示第"+(i+1)+"个广告"); break; } } } this_da = random_da(); </script>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn