JavaScript write a Div pop-up page dialog _javascript tips

Source: Internet
Author: User
Tags border color
Search the code on the Web, make some changes to that,
Fix can't customize color, fix IE8 error, and other minor bugs compatible with Ie6~8 and Firefox
You can customize
Tip Window Caption Height
The border color of the prompt window
The caption color of the prompt window
Tip Window Title Background color
The background color of the hint content
Prompt for content text alignment
Feature can pop a large div cover page (ie transparent) and then display a small div in the center of the screen
Can be used as a function hint operation tips and announcements, etc.
Hint content can make HTML tagged text, but also a page link
Copy Code code as follows:

function MessageBox ()
{
This.titleheight = "21"; Tip Window Caption Height
This.bordercolor = "#666699"; The border color of the prompt window
This.titlecolor = "#1259a4"; The caption color of the prompt window
This.titlebgcolor = "#e4f1fb"; Tip Window Title Background color
This.bgcolor = "#FFFFFF"; The background color of the hint content
This. Msgalign= "left";

This. Show=function (title, MSG, FRAMESRC, W, h)
{
var iwidth = document.documentElement.clientWidth;
var iheight = document.documentelement.clientheight+document.documentelement.scrolltop*2;
var bgobj = document.createelement ("div");
BgObj.style.cssText = "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 ("div");
MsgObj.style.cssText = "position:absolute;font:11px ' song Body"; 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.cssText = "margin:0px;border:0px;padding:0px;";
table.cellspacing = 0;
var tr = Table.insertrow (-1);
var titlebar = Tr.insertcell (-1);
TitleBar.style.cssText = "; width:" + (w-84) + "Px;height:" +this.titleheight+ "px;text-align:left;padding:3px;margin:0 Px;font:bold 13px ' song body '; 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.cssText = "Cursor:pointer; Padding:2px;background-color: "+ this.titlebgcolor;
closebtn.innerhtml = "<span style=" Font-size:10pt;color: "+this.titlecolor+"; "style=" Font-size:10pt;color: "+ This.titlecolor+ ";" Id= ' closebtn ' >x close the window ";
Closebtn.onclick = function () {
Document.body.removeChild (Bgobj);
Document.body.removeChild (Msgobj);
}
var MsgBox = Table.insertrow ( -1). InsertCell (-1);
MsgBox.style.cssText = "font:10pt ' song Body ';";
Msgbox.colspan = 2;

if (framesrc!= "")
{
msg = "<iframe name= ' Frmalertwin ' id= ' Frmalertwin ' src=" About:blank "src=" About:blank "frameborder=0 marginwidth=0 Marginheight=0 style= ' Height: ' + (h-this.titleheight-10) + ' px;width:100%; ' ></iframe> ";
}
msgbox.innerhtml = "<div style=" \ style= "\" "Text-align:" +this. msgalign+ ">" +msg+ "</div>";

if (document.getElementById ("Frmalertwin")!= null)
{
document.getElementById ("Frmalertwin"). src = framesrc;
}


function GetEvent () {
return Window.event | | Arguments.callee.caller.arguments[0];
}
}
}

Call mode
var msgbox=new MessageBox ();
MsgBox. Show (' in-station announcement ', "small hint", "", 500,220);///parameter: caption, content (hint is nullable when connecting page), Connection page address (use text is nullable), width, height
It is important to note that if the page is loaded with a pop-up prompt please place the calling code after the body tag, otherwise the error occurs next to 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.