JavaScript based on time segment pop-up ads sample

Source: Internet
Author: User

Example

The code is as follows Copy Code

<script>
Determine if the date is greater than today, such as Islaterdate ("2014-10-1") returns True
function Islaterdate (d) {
try{
var now = new Date ();
var Datearr = D.split ("-");
var arrlen = datearr.length;
Now.setfullyear (Now.getyear (), Now.getmonth (), now.getdate ());
var checkdate = new Date ();
Checkdate.setfullyear (Datearr[0], datearr[1]-1, datearr[2]);
var nowtime = Now.gettime ();
var checktime = Checkdate.gettime ();
if (Nowtime < Checktime) {
return true;
}else{
return false;
}
}catch (e) {return false;}
}
if ((location.href== "/" | | location.href== "http://www.111cn.net/") && islaterdate ("2014-10-1"))
{window.open ("/include/ad.html", "Carnival of 11", "height=400,width=400,left=" + (screen.availwidth-400)/2 + ", top=" + ( screen.availheight-400)/2 + "; Toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no");
</script>

This will pop-up ads in the specified time range, and of course, as with Cookies server script can be set, the following way to see a cookie

The code implements a window that pops up every 24 hours:

The code is as follows Copy Code

function Openpopup () {
Document.writeln ("  <script language=javascript>");
Document.writeln ("window.open" ( ' Http://www.111cn.net ') ");
Document.writeln ("</script\>");
}

Function Get_cookie (name) {
var search = name + "="
var returnvalue = "";
if (Document.cookie.length > 0) {
offset = document.cookie.indexOf (search)
if (offset!=-1) {
offset = se Arch.length
End = Document.cookie.indexOf ('; ', offset);
if (end = = 1)
end = Document.cookie.length;
Retur Nvalue=unescape (document.cookie.substring (offset, end))
}

return returnvalue;
}

Function ninedns_com () {
if (Get_cookie (' popped ') = = ') {
Openpopup ()
document.cookie= ' Popped=yes '
}
}
Ninedns_com ()

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.