Implementation Code of regular display advertisement in js [tested]

Source: Internet
Author: User

Copy codeThe Code is as follows:
<Script type = "text/javascript">
Function strToDate (str, ext ){
If (str = null | str = '') return;
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;
}
Start = "2012-02-24 ";
End = "2012-02-27 ";
Var date = new Date ();
Var start = strToDate (start );
Var end = strToDate (end, false );
// Document. write start. toString ();
Str = "ad 1 ";
Str2 = "Ad 2 ";
If (date> start & date <end ){
Document. write (str );
} Else {
Document. write (str2 );
}
</Script>

It should be noted that this is determined based on the time of the client,
Start = "2012-02-24 ";
End = "2012-02-27 ";
Actually shown in the last two days of the 1949th and 1949th
DEMO code:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <ptml xmlns = "http://www.w3.org/1999/xhtml"> <pead> <meta http-equiv =" content-Type "content =" text/html; charset = gb2312 "> <title> display advertisement _ script house in JS for a specific time period </title> <meta name =" keywords "content =" JS advertisement code, CSS navigation menu, FLSH Focus Image Code "/> <meta name =" description "content =" provides you with-JS advertisement code, CSS navigation menu, FLSH Focus Image Code and webpage special effect code "/> </pead> <body> </ptml>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]

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.