Rewrite alert and use the modal window to enhance alert.

Source: Internet
Author: User

Why rewrite alert?

Prompts are frequently displayed in the project. The prompt text is diverse and must be displayed as needed.

 

Demo address

Alert rewrite code

<SCRIPT>
VaR winalert = Window. Alert;
Window. Alert = function (MSG, Dr ){
VaR revalue = NULL;
If (DR ){
VaR OBJ = Document. createelement ("span ");
OBJ. innerhtml = MSG;
OBJ. style. Position = "absolute ";
OBJ. style. fontsize = "9pt ";
OBJ. style. Left = "0px ";
OBJ. style. Top = "0px ";
OBJ. style. zindex = "9999 ";
OBJ. style. Visibility = "hidden ";
Document. Body. appendchild (OBJ );
VaR winwidth = obj. offsetwidth;
VaR winheight = obj. offsetheight;
Dr. Push (MSG );
VaR REV = Window. showmodaldialog ("msg.htm? "+ Math. Random (), Dr," dialogwidth: "+ (winwidth + 20) +" PX; dialogheight: "+ (winheight + 70) +" PX ");
If (Rev! = Undefined) revalue = rev;
} Else {
Winalert (MSG );
}
Return revalue;
}
</SCRIPT>

Call Code

 

<Input type = "button" value = "test" onclick = "alert ('You cannot prove your innocence by blocking your neighbors. your neighbors are used to prove your innocence. Your neighbors are used to prove your ', ['confirmed', 'cancel', 'reset', 'Return ']) "/>

<Input type = "button" value = "test" onclick = "alert ('You cannot prove your innocence by blocking your neighbors. tell your neighbors to prove your innocence and your neighbors to prove your ') "/>

Source code download

 

Modal window display page

 

 

 

<! Doctype HTML public "-// W3C // dtd html 4.01 frameset // en" "http://www.w3.org/TR/html4/frameset.dtd">
<HTML>

<Head>
<Meta http-equiv = "content-language" content = "ZH-CN">
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<Title> prompt </title>
<Script language = "JavaScript" type = "text/JavaScript">
Function window. onload (){

VaR bus = Window. dialogarguments;
If (bus. length> 0 ){
For (I = 0; I <bus. Length-1; I ++ ){
VaR btuobj = Document. createelement ("input ");
Btuobj. type = "button ";
Btuobj. value = "" + bus [I] + "";
Btuobj. style. marginleft = "2px ";
Btuobj. style. marginright = "2px ";
Btuobj. onclick = function () {window. returnvalue = event. srcelement. value; window. Close ();}
Buttonbox. appendchild (btuobj );
}


} Else {
VaR btuobj = Document. createelement ("input ");
Btuobj. type = "button ";
Btuobj. value = "OK ";
Btuobj. onclick = function () {window. returnvalue = event. srcelement. value; window. Close ();}
Buttonbox. appendchild (btuobj );
}
Msgbox. innerhtml = bus [bus. Length-1];
}
 
Function reset (){
// Window. returnvalue = event. value;
Self. Close ();
}
</SCRIPT>
</Head>

<Body style = "background-color: buttonface; margin: 0px" scroll = "no">

<Div id = "outbox">
<Div style = "font-size: 9pt; line-Height: 12pt; padding: 10px" id = "msgbox">
</Div>
<Div style = "padding-left: 10px; padding-Right: 10px; text-align: Center" id = "buttonbox">
</Div>
</Div>
</Body>

</Html>

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.