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>