본문 바로가기
Javascript

window.alert override

by windrises 2008. 10. 16.
<script>
 window['alert'] = function(msg){
  if( document.getElementById("alert") == null ){
 
   var cw = parseInt(document.documentElement.clientWidth);
   var ch = parseInt(document.documentElement.clientHeight);
   var _top = ch/2 - 50;
   var _left = cw/2 - 150;
    var div = document.createElement('div');
    div.id = "alert";
    div.style.width = "300px";
    div.style.height = "100px";
    div.style.border = "5px solid #000";
    div.style.fontSize = "9pt";
    div.style.zIndex = "100";
    div.style.position = "absolute";
    div.style.top = _top +"px";
    div.style.left = _left +"px";
    var layout = "<div style='text-align:center;margin-top:20px;position:relative' id='alert-msg'>" + msg + "</div>";
    layout += "<div style='text-align:center;margin-top:10px;bottom:10px;position:absolute;width:100%'><a href=\"javascript:void(document.getElementById('alert').style.display='none')\">[close]</a></div>";
    div.innerHTML = layout;
    document.body.appendChild(div);
  }else{
   var cw = parseInt(document.documentElement.clientWidth);
   var ch = parseInt(document.documentElement.clientHeight);
   var _top = ch/2 - 50;
   var _left = cw/2 - 150;
    var div = document.getElementById("alert");
    div.style.top = _top +"px";
    div.style.left = _left +"px";
   document.getElementById("alert-msg").innerHTML = msg;
   document.getElementById("alert").style.display = "";
  }
  
 };

</script>
<a href="javascript:window.alert('Hello world')">click</a>

'Javascript' 카테고리의 다른 글

JS for...in 문..  (0) 2012.12.27
jQuery api & samples  (1) 2012.11.22
js 페이징과련 함수  (1) 2008.05.09