0 Replies - 869 Views - Last Post: 08 March 2013 - 03:02 AM

#1 Addio569  Icon User is offline

  • D.I.C Regular

Reputation: 3
  • View blog
  • Posts: 316
  • Joined: 26-November 08

How can I amend this script to close with 'onkeypress'

Posted 08 March 2013 - 03:02 AM

I have made a buzzer that brings up a custom javascript alert (found on the web) when it is activated you have to click an 'OK' button to get rid of it, how do I add the ability to close it by pressing the enter key as well??

here is the script:

<script>
var message;
function customAlert(message)
{
window.onresize = resizeCheck;
function resizeCheck()
{
 
winX = window.innerWidth;
winY = window.innerHeight; 
modelX = (winX/2)-(920/2)+document.body.scrollLeft;
modelY = (winY/2)-(920/2)+document.body.scrollTop;
var _elm=document.getElementById('overlay');
_elm.style.width=winX+"px";
_elm.style.height=winY+"px";
var _elm=document.getElementById('alert');
_elm.style.left=modelX+"px";
_elm.style.top=modelY+"px";
}
winX = window.innerWidth;
winY = window.innerHeight; 
//alert(document.body.scrollTop);
modelX = (winX/2)-(920/2)+document.body.scrollLeft;
modelY = (winY/2)-(920/2)+document.body.scrollTop;
winX+=document.body.scrollLeft;
winY+=document.body.scrollTop;
var overlay = document.createElement('div');
   overlay.setAttribute("id","overlay");
   overlay.setAttribute("class", "overlay");
   document.body.appendChild(overlay);

var box = document.createElement('div');
   box.setAttribute("id","alert");
   box.innerHTML='<center><div id="button2" ><div id="alert2"><span class="message2">'+message+'</span></div><input type="button" id="ok1" value="OK" ></div></center>';
   document.body.appendChild(box);   
//css
var sheet = document.createElement('style')
sheet.innerHTML = ".overlay{background-color: #FFFFFF;   opacity: .5;   filter: alpha(opacity=70);   position:absolute; top: 0; left: 0;   width:"+winX+"px; height: "+winY+"px;   z-index: 99999;} #alert{width:900px; height:645px; background:#000000; position:absolute;left: "+modelX+"px;top: "+modelY+"px; z-index: 999999;border-radius:3px;border:1px; box-shadow:1px 2px 5px #676767;}#ok1{position:absolute;bottom:10px;left:430px;cursor:pointer; color:black;font:bold 13px sans-serif;text-transform:uppercase;border:none;border-radius:50px;}#alert2 span {font:500px sans-serif;color:#FF0000;display:inline-block;margin-top:50px;}";
document.body.appendChild(sheet);
var element=document.getElementById("ok1");
element.addEventListener('click',resume,false)
function resume()
{
 
 document.body.removeChild(overlay);
 document.body.removeChild(box);
 document.body.removeChild(sheet);
}
}
</script>


Is This A Good Question/Topic? 0
  • +

Page 1 of 1