Javascript achieves automatic div layer blocking in 5 seconds, and js5 blocks div in seconds

Source: Internet
Author: User

Javascript achieves automatic div layer blocking in 5 seconds, and js5 blocks div in seconds

This article describes how to automatically block the div layer in five seconds in JavaScript. Share it with you for your reference. The specific implementation method is as follows:

Copy codeThe Code is as follows: <Head>
<Title> JavaScript automatically blocks the div layer within 5 seconds </title>
<Style type = "text/css">
<! --
# Sort soraddiv {position: absolute; height: 1; width: 1; top: 0; left: 0 ;}
-->
</Style>
</Head>
<Body>
<Script language = "JavaScript1.2">
AdTime = 5; // the expected time of the blocked window
ChanceAd = 1;
Var ns = (document. layers );
Var ie = (document. all );
Var w3 = (document. getElementById &&! Ie );
AdCount = 0;
Function initAd (){
If (! Ns &&! Ie &&! W3) return;
If (ie) adDiv = eval ('document. all. soraddiv. style ');
Else if (ns) adDiv = eval ('document. layers ["soraddiv"] ');
Else if (w3) adDiv = eval ('document. getElementById ("soraddiv"). style ');
RandAd = Math. ceil (Math. random () * chanceAd );
If (ie | w3)
AdDiv. visibility = "visible ";
Else
AdDiv. visibility = "show ";
If (randAd = 1) showAd ();
}
Function showAd (){
If (adCount <adTime * 10) {adCount + = 1;
If (ie) {documentWidth = document. body. offsetWidth/2 + document. body. scrollLeft-20;
Export entheight = document. body. offsetHeight/2 + document. body. scrollTop-20 ;}
Else if (ns) {documentWidth = window. innerWidth/2 + window. pageXOffset-20;
Export entheight = window. innerHeight/2 + window. pageYOffset-20 ;}
Else if (w3) {documentWidth = self. innerWidth/2 + window. pageXOffset-20;
Export entheight = self. innerHeight/2 + window. pageYOffset-20 ;}
AdDiv. left = documentWidth-200; adDiv. top = documentHeight-200;
SetTimeout ("showAd ()", 100);} else closeAd ();
}
Function closeAd (){
If (ie | w3)
AdDiv. display = "none ";
Else
AdDiv. visibility = "hide ";
}
Onload = initAd;
</Script>
<Div id = "soraddiv" style = "visibility: hidden">
<Table width = "450" height = "350" bgcolor = "008000"> <tr> <td>
<Table width = "445" height = "345" bgcolor = "F0FFF0"> <tr> <td>
<Center> welcome to www.CsrCode.cn! <BR> This window will be automatically blocked in 5 seconds </center>
</Td> </tr> </table> </div>
</Body>
</Html>

I hope this article will help you design javascript programs.

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.