Autoclose Alert
Answer : jsFiddle Demo This functionality is not possible with an alert. However, you could use a div function tempAlert(msg,duration) { var el = document.createElement("div"); el.setAttribute("style","position:absolute;top:40%;left:20%;background-color:white;"); el.innerHTML = msg; setTimeout(function(){ el.parentNode.removeChild(el); },duration); document.body.appendChild(el); } Use this like this: tempAlert("close",1000); You can't close alert any how . But you can use div To show your alert MSG. function Mymsg(msg,duration) { var alt = document.createElement("div"); alt.setAttribute("style","position:absolute;top:50%;left:50%;background-color:white;"); alt.innerHTML = msg; setTimeout(function(){ alt.parentNode.removeChild(alt); },duration); document.body.appendChild(alt); } You can use as : Mymsg('close',2000) jsFiddle Demo Basically you...