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.