jsFiddle Demo
Basically you can imitate an alert box with a popup window and close it whenever you want, call the following function:
function myAlert(msg,title,width,height,timeout) {
var myWindow = window.open("", "",`width=${width},height=${height},left=${(window.outerWidth/2-width/2)},top=0`); //open a new popup at the top height and middle width of the current window
myWindow.document.write(`<center id="msg">`+msg+`</center>`); //write the message you want to display
myWindow.document.title = title; //write the title of the alert box
setTimeout(function(){
myWindow.close(); //close the popup
},timeout||3000) //in 3 secondes (3000 milliseconds)
}
by the way if you want to close the alert on call, just use define the variable "myWindow" earlier (out of myAlert() function) as a global variable and then call myWindow.close();
once you already called myAlert() and remove
setTimeout(function(){
myWindow.close(); //close the popup
},timeout||3000) //in 3 secondes (3000 milliseconds)
from the function myAlert()