Self-made pop-up content box JS Code

Source: Internet
Author: User
// Xingmai namespace

If (! Xingmai)

VaR xingmai = {};


// Content window

Xingmai. contentbox =

{

// Create a window

Createbox: function ()

{

// Create a form

VaR contentbox = {};


// ID

Contentbox. ID = NULL;


// Window title

Contentbox. Title = NULL;


// Window width

Contentbox. width = NULL;


// Window height

Contentbox. Height = NULL;


// Left pixel of window

Contentbox. Left = NULL;


// Top pixel of the window

Contentbox. Top = NULL;


// Class definition

Contentbox. classname = NULL;


// Default Value

Contentbox. Common = {

Width: 500,

Height: 400,

Left: (document.doc umentelement. clientwidth-contentbox. width)/2 +
Document.doc umentelement. scrollleft, // Error

Top:
(Document.doc umentelement. clientheight-contentbox. Height)/2 +
Document.doc umentelement. scrolltop // Problem

};

// Create a box

Contentbox. Create = function ()

{

// Alert ("");

// Create a Main Interface

VaR newbox = Document. createelement ("Div ");

Newbox. setattribute ("ID", contentbox. ID );

With (newbox. Style)

{

Position = "absolute ";

Z index = "9999 ";

Width = contentbox. Width + "PX ";

Height = contentbox. height + "PX ";

Top = contentbox. Top;

Left = contentbox. Left;

}

// Newbox. setattribute ("style", "width:" + contentbox. Width + "PX; Height:" + contentbox. height + "PX ;");

If (contentbox. classname! = NULL)

Newbox. setattribute ("classname", contentbox. classname );


// Create the title bar and delete button

VaR titlespan = Document. createelement ("Div ");

With (titlespan. Style)

{

Height = "20px ";

Textalign = "Left ";

Verticalalign = "Middle ";

}

// Titlespan. setattribute ("style", "height:" + "35" + "PX ;");

Titlespan. setattribute ("class", "contenttitlespan ");

VaR spandiv = Document. createelement ("Div ");

With (spandiv. Style)

{

Width = contentbox. Width-30 + "PX ";

Stylefloat = "Left ";

Textalign = "Left ";

}

Spandiv. appendchild (document. createtextnode (contentbox. Title ));

Titlespan. appendchild (spandiv );


VaR closediv = Document. createelement ("Div ");

With (closediv. Style)

{

Width = "20px ";

Stylefloat = "right ";

Textalign = "right ";

}

VaR closebutton = Document. createelement ("");

Closebutton. setattribute ("href ","#");

Closebutton. appendchild (document. createtextnode ("× "));

$ Addhandler (closebutton, "click", function () {xingmai. contentbox. killbox (contentbox. ID );});

Closediv. appendchild (closebutton)

Titlespan. appendchild (closediv );

Newbox. appendchild (titlespan );


// Create an IFRAME

VaR IFRAME = Document. createelement ("iframe ");

IFRAME. setattribute ("class", "contentiframe ")

IFRAME. setattribute ("src", contentbox. url );

IFRAME. setattribute ("frameborder", "0", 0 );

IFRAME. setattribute ("scrolling", "no ");

With (IFRAME. Style)

{

Border = "0 ";

Width = "100% ";

Height = (contentbox. Height-20) + "PX ";

}

Newbox. appendchild (IFRAME );


Return newbox;

};


// Create ID

Contentbox. createid = function ()

{

VaR now = new date ();

Return "contentbox" + now. getfullyear () + now. getmonth () + now. getday ()
+ Now. gethours () + now. getminutes () + now. getseconds () +
Now. getmilliseconds ();

};


// Display window

Contentbox. Show = function ()

{

// Process the default value

Contentbox. ID = contentbox. ID = NULL? Contentbox. createid (): contentbox. ID;

Contentbox. Title = contentbox. Title = NULL? "Content System window": contentbox. title;

Contentbox. url = contentbox. url = NULL? "About: blank": contentbox. url;

If (isnan (contentbox. width) | contentbox. width = NULL)

Contentbox. width = contentbox. Common. width;

If (isnan (contentbox. Height) | contentbox. Height = NULL)

Contentbox. Height = contentbox. Common. height;

If (isnan (contentbox. Left) | contentbox. Left = NULL)

Contentbox. Left = contentbox. Common. Left;

If (isnan (contentbox. Top) | contentbox. Top = NULL)

Contentbox. Top = contentbox. Common. Top;


// Create a window and display it

VaR add = contentbox. Create ();

Document. getelementsbytagname ("body"). Item (0). appendchild (ADD );

};


Return contentbox;

},


// Delete the window

Killbox: function (ID)

{

VaR box = Document. getelementbyid (ID );

If (box)

Box. parentnode. removechild (box );

}

};

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.