사용자 정의alert 프롬프트 상자

4464 단어 alert
function selfAlert(msgstr,timer)
{
	    var alertValue = 0; 
	
	    var h = screen.availHeight;
	    var w = screen.availWidth;
	    var dv = document.createElement("div");
	    dv.setAttribute('id','bg');
	    dv.style.height = h + "px";
	    dv.style.width = w + "px";
	    dv.style.zIndex = "1111";
	    dv.style.top = 0;
	    dv.style.left = 0;
	    dv.style.background = "#fff";
	    dv.style.filter = "alpha(opacity=0)";
	    dv.style.position = "absolute";
	    document.body.appendChild(dv);
	
	    var dvMsg = document.createElement("div");
	    dvMsg.style.position = "absolute";
	    dvMsg.setAttribute('id','msg');
	    dvMsg.style.width = "140px";
	    dvMsg.style.height = "50px";
	    dvMsg.style.top="30%";
	    dvMsg.style.left="40%";
	    dvMsg.style.background = "white";
	    dvMsg.style.zIndex = "1112";

	    strHtml =  "<table width='200' height='25' border='0' cellspacing='0' cellpadding='0' align='center'>"
	    strHtml += "    <tr height='25' style='line-height:25px;'>"
	    strHtml += "        <td width='250' title=' ' style='cursor:move;background:#CFD7EC url(title_bg_left.gif) no-repeat top left;' onmousedown='oMove(parentNode.parentNode.parentNode.parentNode);'>"
	    strHtml += "            <font style='font-size:12px;font-weight:bold;color:#000;margin-left:10px;'> </font></td>"
	    strHtml += "        <td width='30' style='background:#CFD7EC url(title_bg_right.gif) no-repeat right top;'>"
	    strHtml += "            <img src='close.gif' style='margin-right:3px;cursor:hand;' onclick='imgClose();'><td></tr>"
	    strHtml +=  "</table>"
	    strHtml +=  "<table width='200' height='50' border='0' cellspacing='0' cellpadding='0' align='center' style='border:1px solid #343434'>"
	    strHtml += "    <tr height='50' bgcolor='#F4F4F4'><td width='' style='padding-left:10;'></td>"
	    strHtml += "        <td width='200' align='center'>" + msgstr + "</td></tr>"
	    strHtml += "    <tr height='27'><td colspan='2' style='background:#F4F4F4;padding-top:0px;' valign='top' align='center'>"
	    strHtml += "         <input type='button' value=' &nbsp; ' style='width:70;' onclick='btnclick()'></td></tr>"
	    strHtml += "</table>"
	    dvMsg.innerHTML = strHtml;
	    document.body.appendChild(dvMsg);
	
	    imgClose = function (){
	        alertValue = 2; 
	        document.body.removeChild(dv);
	        document.body.removeChild(dvMsg);
	    };
	    btnclick = function (){
	        alertValue = 1; 
	        document.body.removeChild(dv);
	        document.body.removeChild(dvMsg);
	    };
	    
	    remove = function ()
	    {
	        if(alertValue==0){
	            document.body.removeChild(dv);
	            document.body.removeChild(dvMsg);
	        }
	    };

	    setTimeout("remove()",timer);
	    
	    oMove = function(obj) {
	        var otop,oleft;
	        otop = event.y - obj.offsetTop;
	        oleft = event.x - obj.offsetLeft;
	        obj.setCapture();
	
	        obj.onmousemove  = function()
	        {
	            obj.style.left = event.x - oleft;
	            obj.style.top = event.y - otop;
	        };
	        obj.onmouseup  = function()
	        {
	            obj.onmousemove = null;
	            obj.style.filter = null;
	            obj.releaseCapture();
	        };
	    };
};

좋은 웹페이지 즐겨찾기