Js pulled from Netease calls the ad display file (random probability) _ ad code

Source: Internet
Author: User
The js Code obtained from Netease calls the ad display file (random probability). The probability of display depends mainly on the random number. For more information, see. Call the advertisement display file from js pulled by Netease
Only a few lines of code below can randomly display flash and gif ads, not bad

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, and img represent three different ad Modes
// The number of 200 is the probability of occurrence.
Columns02 [0] = new column02 ("http://smsimg.163.com/honey/honey_ad.swf", "", 200, "flash"); // ad
Columns02 [1] = new column02 ("http://smsimg.163.com/honey/honey_photo.swf", "", 800, "flash"); // upload images for rent-free monthly
Columns02 [2] = new column02 ("http://smsimg.163.com/honey/honey_gold.swf", "", 800, "flash"); // login to send 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 ();


The larger the chance, the higher the chance of displaying the code.

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 + "display number" + (I + 1) + "ad"); break ;}}} this_da = random_da (); script
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]

Related Article

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.