[JS] Custom Alert 띄우기
Javascript의 alert을 예쁘게(?) 띄우는 스크립트 입니다.

*.js파일이나 헤더 스크립트 영역에 다름 함수를 선언합니다.
        //경고창 레이어로 띄우기
var AlertCallBackFunctions;
function Alert(msg, func)
{
AlertCallBackFunctions = func;
var divAlertForBlind = document.getElementById("divAlertForBlind");
var divAlert = document.getElementById("divAlert");
var divAlertMsg = document.getElementById("divAlertMsg");

if(divAlertForBlind != null && divAlert != null)
{
                divAlertMsg.innerHTML = msg;

divAlertForBlind.style.display = "block";
divAlert.style.display = "block";
document.oncontextmenu = function () {return false;};
document.onselectstart = function () {return false;};
document.ondragstart = function () {return false;};
document.onkeydown = function () {
if(event.keyCode == 13 || event.keyCode == 32) //Enter or Space Key Event
{
AlertHide();
return false;
}
};
}
}
//경고창 지우기
function AlertHide()
{
var divAlertForBlind = document.getElementById("divAlertForBlind");
var divAlert = document.getElementById("divAlert");
if(divAlertForBlind != null && divAlert != null)
{
divAlert.style.display = "none";
divAlertForBlind.style.display = "none";
if(AlertCallBackFunctions != null)
AlertCallBackFunctions.call();
document.oncontextmenu = null;
document.onselectstart = null;
document.ondragstart = null;
document.onkeydown = null;
}
}
html body 영역에 Alert 레이어 HTML디자인을 합니다.
        <!-------------------- Alert Layer 시작 -------------------->
<div id="divAlertForBlind" class="AlertForBlind"></div>
<div id="divAlert" class="Alert">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" style="background-color:#50596E;border: 1px solid #1D2028;">
<tr>
<td class="title2" style="padding:3px;background-color:#2C2C2C; border-bottom:solid 1px #595959;">
<img src="
/images/icon_confirm.gif" width="22" height="21" hspace="6" align="absmiddle">Alert Message
</td>
</tr>
<tr>
<td
style="padding:10px;" align="center"><div id="divAlertMsg" class="title3"></div></td>
</tr>
<tr>
<td height=
"35" align="center">
<img onclick=
"AlertHide();" style="cursor:hand;" src="/images/btn_ok_off.gif" width="124" height="32" border="0" onmouseover="this.src='/images/btn_ok_on.gif'" onmouseout="this.src='/images/btn_ok_off.gif'" alt="확인"/>
</td>
</tr>
</table>
</div>
<!-------------------- Alert Layer 끝 -------------------->
Alert창을 호출할땐 다음과 같이 실행합니다.
//경고창의 [확인]버튼을 누른후의 동작을 두번째 인자에 스크립팅합니다.
//첫번째 방법
Alert("경고입니다.", function() {history.back();});




//두번째 방법
function CallBackFuncs()
{
history.back();
}
Alert("경고입니다.", CallBackFuncs);
이건 CSS Style 코드... 입맛에 맞게 바꾸면 되겠죠.

.AlertForBlind 
{
cursor:default;
text-align:center;
display:none;
width: 100%;
height: 100%;
z-index: 100;
position: absolute;
left: 0px;
top: 0px;
background-color:Black;
filter:Alpha(Opacity=50);
}

.Alert
{
cursor:default;
background-color:#959FB9;
padding:5px;
display:none;
width: 300px;
z-index: 200;
position: absolute;
left: expression(document.body.offsetWidth / 2 - 150);
top: expression(document.body.offsetHeight / 2 - this.offsetHeight + 50);
}


IE7에서만 테스트했으므로 다른 브라우저에서도 잘 될지는 모르겠네요. 걍 간단히 사용할때만 쓰시면 될거같고
제대로된 플랫폼에서 사용하시려면 YUI (Yahoo UI Script Frameword입니다.)의 Panel Component를 사용하시는게 깔끔할겁니다.
by 귀뫄뉘 | 2007/11/22 13:21 | ┣ programming | 트랙백 | 덧글(2)
트랙백 주소 : http://kuimoani.egloos.com/tb/1030414
☞ 내 이글루에 이 글과 관련된 글 쓰기 (트랙백 보내기) [도움말]
Commented by 꼬출든남자 at 2007/11/23 01:06
오오오오 예쁘다.. +_+
Commented by 귀뫄뉘 at 2007/11/23 10:31
오오 오랜만이에요 ㅎㅎㅎ

:         :

:

비공개 덧글