JavaScript automatically closes the window

Source: Internet
Author: User

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

<title>javascript Auto Close window </title>

<meta http-equiv= "Content-type" content= "text/html;charset=gb2312" >

<body>

<input type= "button" value= "Popup Alert box automatically closes" onclick= "alert (' Do not click OK three seconds after auto-off ') ' >

<script> window.onload = function () {Alert (' open page Auto popup box! ‘);} </script>

<script>

Automatically close the Prompt box

function Alert (str) {

var Msgw,msgh,bordercolor;

msgw=350;//the width of the prompt window

msgh=80;//the height of the prompt window

TITLEHEIGHT=25//Tip window Title height

Bordercolor= "#336699";//Border color of the hint window

Titlecolor= "#99CCFF";//title Color of the hint window

var swidth,sheight;

Get the current window size

Swidth = Document.body.offsetWidth;

Sheight = Document.body.offsetHeight;

Background Div

var bgobj=document.createelement ("div");

Bgobj.setattribute (' id ', ' alertbgdiv ');

bgobj.style.position= "Absolute";

bgobj.style.top= "0";

Bgobj.style.background= "#E8E8E8";

Bgobj.style.filter= "Progid:DXImageTransform.Microsoft.Alpha (style=3,opacity=25,finishopacity=75";

bgobj.style.opacity= "0.6";

bgobj.style.left= "0";

BgObj.style.width = swidth + "px";

BgObj.style.height = sheight + "px";

BgObj.style.zIndex = "10000";

Document.body.appendChild (Bgobj);

Create a div for the cue window

var msgobj = document.createelement ("div")

Msgobj.setattribute ("id", "alertmsgdiv");

Msgobj.setattribute ("Align", "center");

msgobj.style.background= "White";

Msgobj.style.border= "1px solid" + bordercolor;

MsgObj.style.position = "absolute";

MsgObj.style.left = "50%";

Msgobj.style.font= "12px/1.6em Verdana, Geneva, Arial, Helvetica, Sans-serif";

Distance from left and top of window

MsgObj.style.marginLeft = " -225px";

Window is rolled away high + (screen available working area high/2)-150

MsgObj.style.top = document.body.scrolltop+ (WINDOW.SCREEN.AVAILHEIGHT/2) -150 + "px";

MsgObj.style.width = MSGW + "px";

MsgObj.style.height = msgh + "px";

msgObj.style.textAlign = "center";

MsgObj.style.lineHeight = "25px";

MsgObj.style.zIndex = "10001";

Document.body.appendChild (Msgobj);

Tip Information Title

var title=document.createelement ("H4");

Title.setattribute ("id", "alertmsgtitle");

Title.setattribute ("Align", "left");

title.style.margin= "0";

Title.style.padding= "3px";

Title.style.background = bordercolor;

Title.style.filter= "Progid:DXImageTransform.Microsoft.Alpha (startx=20, starty=20, finishx=100, finishy=100,style= 1,OPACITY=75,FINISHOPACITY=100); ";

Title.style.opacity= "0.75";

Title.style.border= "1px solid" + bordercolor;

Title.style.height= "18px";

Title.style.font= "12px Verdana, Geneva, Arial, Helvetica, Sans-serif";

title.style.color= "White";

Title.innerhtml= "prompt message";

document.getElementById ("Alertmsgdiv"). AppendChild (title);

Prompt information

var txt = document.createelement ("P");

Txt.setattribute ("id", "msgtxt");

Txt.style.margin= "16px 0";

txt.innerhtml = str;

document.getElementById ("Alertmsgdiv"). appendchild (TXT);

Set Shutdown time

Window.settimeout ("Closewin ()", 2000);

}

function Closewin () {

Document.body.removeChild (document.getElementById ("Alertbgdiv"));

document.getElementById ("Alertmsgdiv"). RemoveChild (document.getElementById ("Alertmsgtitle"));

Document.body.removeChild (document.getElementById ("Alertmsgdiv"));

}

</script>

</body>



This article is from the "wind up with the Wind Stop" blog, please be sure to keep this source http://hww9011.blog.51cto.com/3545422/1582154

JavaScript automatically closes the window

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.