Javascript Sina advertising implementation code

Source: Internet
Author: User

Today, I checked Sina's Js Code It is good to find a back-cast advertising code from both the perspective of learning and use, but it will be blocked if it finds a problem.
The following is the specific JS Code. Copy code The Code is as follows :/*
Carousel back-cast rotatorpb v3.1
Update by dakular <shuhu@staff.sina.com.cn>
Format: New rotatorpb (AD array)
Note: The first access appears randomly, and then the access sequence is carousel; expired ads are automatically filtered; cookie time is 24 hours; when the number of commercial ads is insufficient
*/
If (typeof (rotatorpb )! = 'Function '){
VaR rotatorpb = function (RAD ){
This. ary = new array ();
This. Date = new date ();
This. W = rad. width;
This. H = rad. height;
This. num = rad. Num;
This. O = rad. length;
This. ID = rotatorpb. ID ++;
This. M = 'rpb _ '+ this. ID;
This. n = new array ();
This. L = new date ();
This. E = 0;
VaR F;
VaR d = false;
VaR nn = 0;
// Filter invalid ads
For (VAR I = 0; I <rad. length; I ++ ){
VaR start = rotatorpb. strtodate (RAD [I] [2]. replace ('<startdate> ',''). replace ('</startdate> ',''));
VaR end = rotatorpb. strtodate (RAD [I] [3]. replace ('<enddate> ',''). replace ('</enddate>', ''), true );
If (this. Date> Start & this. Date <End & (this. num = NULL | this. ary. Length <this. Num )){
This. ary. Push ([rad [I] [0], Rad [I] [1], Rad [I] [4]);
}
}
This. O = This. ary. length;
// Obtain the ID
For (VAR I = 0; I <this. O; I ++ ){
F = This. m + '_' + (I + 1 );
G = rotatorpb. G (f );
If (G! = ''){
This. N [I] = g;
D = true;
} Else {
This. N [I] = 0;
}
}
If (! D ){
VaR r = math. Ceil (math. Random () * This. O );
VaR T = This. m + '_' + R;
Rotatorpb. S (T, this. l. gettime (), 1440 );
This. E = R;
If (this. O = 1) {rotatorpb. S ('s _ DL ', R, 1440 );}
// Return R;
} Else {
VaR r = This. N. Join (','). Split (',');
VaR K = R. Sort ();
VaR max = Number (K [K. Length-1]);
VaR min = Number (K [0]);
VaR F;
For (VAR I = 0; I <this. N. length; I ++ ){
If (max = This. N [I]) {
F = I + 1;
Break;
}
}
If (typeof (f )! = 'Undefined '){
G = This. m + '_' + F;
H = Number (rotatorpb. G (g ));
I = F % This. O + 1;
J = This. m + '_' + I;
Rotatorpb. S (J, this. l. gettime (), 1440 );
If (this. O = 1 ){
I =-rotatorpb. G ('s _ DL ');
If (I = 0) {I = 1; rotatorpb. S ('s _ DL ', 1, 1440 );}
Rotatorpb. S ('s _ DL ', I, 1440 );
}
This. E = I;
// Return I;
}
}
// Show ad
If (this. E = 0 | this. ary. Length = 0) return; // if no advertisement is displayed, It is not displayed.
If (this. E =-1) return; // when there is only one advertisement, the first or odd refresh is always displayed.
VaR n = this. The E-1;
VaR btsrc = This. ary [N] [0];
VaR bturl = This. ary [N] [1];
VaR bttype = btsrc. substring (btsrc. Length-3). tolowercase ();
If (bttype = '. js') {// JS
Document. write ('<script language = "JavaScript" type = "text/JavaScript" src = "' + btsrc + '"> </scr' + 'ipt'> '); return;
} Else if (bttype! = 'Htm' & bttype! = 'Tml '){
Sinabturl = "http://d1.sina.com.cn/d1images/pb/pbv4.html? "+ Bturl +" $ {} "+ bttype +" $ {} "+ btsrc;
} Else {
Sinabturl = btsrc;
}
Try {
Aryadseq. Push ("openwindowback ()");
} Catch (e ){
Openwindowback ();
}
If (this. ary [N] [2]! = "") {// Monitoring count
VaR oimg = new image ();
Oimg. src = This. ary [N] [2];
}
};
Rotatorpb. ID = 1;
Rotatorpb. G = function (n ){
VaR c = Document. Cookie. Split (";");
For (VAR I = 0; I <C. length; I ++ ){
VaR d = C [I]. Split ("= ");
If (d [0] = N) return Unescape (d [1]);
} Return '';
};
Rotatorpb. S = function (n, V, q ){
VaR L = new date ();
VaR z = new date (L. gettime () + Q * 60000 );
Document. Cookie = N + "=" + escape (v) + "; Path =/; expires =" + Z. togmtstring () + ";";
};
Rotatorpb. strtodate = function (STR, ext ){
VaR arys = new array ();
Arys = Str. Split ('-');
VaR newdate = new date (arys [0], arys [1]-1, arys [2], 9, 0, 0 );
If (EXT ){
Newdate = new date (newdate. gettime () + 1000*60*60*24 );
}
Return newdate;
}
VaR openwindowback = function (){
VaR popupwin2 = open (sinabturl, (window. Name! = "Popupwin2 ")? "Popupwin2": "", "width = 1, Height = 1, Top = 4000, Left = 3000 ");
}
};

Specific call code:Copy codeThe Code is as follows: <SCRIPT src = "rotator_pb.js"> </SCRIPT>
<Script language = JavaScript type = text/JavaScript>
// <! [CDATA [
VaR RPB = new array ();
RPB. num = 2; // Number of carousel broadcasts
<! -- 2220e7b88d58 --> // ad Creation
RPB. Push (["http://img.jb51.net/demo/images/beitou.jpg", "http://www.jb51.net", "<startdate> </startdate>", "<enddate> </enddate>", ""]);
<! -- $ Litong/2009-4-15 ~ 2009-8-15/B $ -->
New rotatorpb (RPB );
//]>
</SCRIPT>

Beitou.jpg is the image address, followed by a link. You can refer to the start date and end date.

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.