JavaScript-written DIV pop-up webpage dialog box _ javascript skills

Source: Internet
Author: User
I have compiled a JavaScript-written DIV. The code found on the Internet in the pop-up webpage dialog box has been modified,
Fixed the issue where custom colors could not be defined, corrected IE8 errors, and other bugs were compatible with IE6 ~ 8. Firefox
Customizable
// The title height of the prompt window
// The border color of the prompt window
// The title Color of the prompt window
// The title background color of the prompt window
// The background color of the prompt content
// Prompt text alignment
Function to bring up a large DIV to cover the page (transparent under IE) and then display a small DIV in the center of the screen
Operation tips and announcements
The text with HTML tags can also be a page Link.

The Code is as follows:


Function MessageBox ()
{
This. titleheight = "21"; // The title height of the prompt window.
This. bordercolor = "#666699"; // The border color of the prompt window.
This. titlecolor = "#1259a4"; // The title Color of the prompt window.
This. titlebgcolor = "# e4f1fb"; // The title background color of the prompt window
This. bgcolor = "# FFFFFF"; // specifies the background color of the prompt content.
This. MsgAlign = "left ";

This. Show = function (title, msg, framesrc, w, h)
{
Var iWidth = document.doc umentElement. clientWidth;
Var iHeight = document.documentelement.clientheight?document.doc umentElement. scrollTop * 2;
Var bgObj = document. createElement ("p ");
BgObj.style.css Text = "position: absolute; left: 0px; top: 0px; width:" + iWidth + "px; height:" + Math. max (document. body. clientHeight, iHeight) + "px; filter: Alpha (Opacity = 30); opacity: 0.3; background-color: #000000; z-index: 101 ;";
Document. body. appendChild (bgObj );

Var msgObj = document. createElement ("p ");
MsgObj.style.css Text = "position: absolute; font: 11px ''; top:" + (iHeight-h)/2 + "px; left:" + (iWidth-w) /2 + "px; width:" + w + "px; height:" + h + "px; text-align: center; border: 1px solid" + this. bordercolor + "; background-color:" + this. bgcolor + "; padding: 1px; line-height: 22px; z-index: 102 ;";
Document. body. appendChild (msgObj );

Var table = document. createElement ("table ");
MsgObj. appendChild (table );
Table.style.css Text = "margin: 0px; border: 0px; padding: 0px ;";
Table. cellSpacing = 0;
Var tr = table. insertRow (-1 );
Var titleBar = tr. insertCell (-1 );
TitleBar.style.css Text = "; width:" + (w-84) + "px; height:" + this. titleheight + "px; text-align: left; padding: 3px; margin: 0px; font: bold 13px ''; color:" + this. titlecolor + "; cursor: move; background-color:" + this. titlebgcolor;
TitleBar. style. paddingLeft = "10px ";
TitleBar. innerHTML = title;
Var moveX = 0;
Var moveY = 0;
Var moveTop = 0;
Var moveLeft = 0;
Var moveable = false;
Var docMouseMoveEvent = document. onmousemove;
Var docMouseUpEvent = document. onmouseup;

TitleBar. onmousedown = function (){
Var evt = getEvent ();
Moveable = true;
MoveX = evt. clientX;
MoveY = evt. clientY;
MoveTop = parseInt (msgObj. style. top );
MoveLeft = parseInt (msgObj. style. left );

Document. onmousemove = function (){
If (moveable)
{
Var evt = getEvent ();
Var x = moveLeft + evt. clientX-moveX;
Var y = moveTop + evt. clientY-moveY;
If (x> 0 & (x + w <iWidth) & y> 0 & (y + h <iHeight ))
{
MsgObj. style. left = x + "px ";
MsgObj. style. top = y + "px ";
}
}
};

Document. onmouseup = function (){
If (moveable)
{
Document. onmousemove = docMouseMoveEvent;
Document. onmouseup = docMouseUpEvent;
Moveable = false;
MoveX = 0;
MoveY = 0;
MoveTop = 0;
MoveLeft = 0;
}
};
}

Var closeBtn = tr. insertCell (-1 );
CloseBtn.style.css Text = "cursor: pointer; padding: 2px; background-color:" + this. titlebgcolor;
CloseBtn. innerHTML = "× Close Window ";
CloseBtn. onclick = function (){
Document. body. removeChild (bgObj );
Document. body. removeChild (msgObj );
}
Var msgBox = table. insertRow (-1). insertCell (-1 );
MsgBox.style.css Text = "font: 10pt '';";
MsgBox. colSpan = 2;

If (framesrc! = "")
{
Msg = "";
}
MsgBox. innerHTML ="

"+ Msg +"

";

If (document. getElementById ("frmAlertWin ")! = Null)
{
Document. getElementById ("frmAlertWin"). src = framesrc;
}


Function getEvent (){
Return window. event | arguments. callee. caller. arguments [0];
}
}
}


Call Method
Var msgbox = new MessageBox ();
Msgbox. show ('intra-site announcement ', "Tips", "", 500,220); // parameter: title, content (blank when prompted to connect to the page ), link the page address (the text can be blank), width, and height
Note that if a prompt is prompted during page loading, put the call code in the body mark; otherwise, an error occurs in IE8.

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.