Is there any way to close a javascript alert()
automatically?
I have an alert
alert(\"Error found\");
I want to close
I updated the style settings, so it shows like a splash screen in the center of your page, and centers the text inside it.
Call it like this:
alertTimeout("System Message
This is a test message
This alert will auto-close",5000)
The function:
function alertTimeout(mymsg,mymsecs)
{
var myelement = document.createElement("div");
myelement.setAttribute("style","background-color: grey;color:black; width: 450px;height: 200px;position: absolute;top:0;bottom:0;left:0;right:0;margin:auto;border: 4px solid black;font-family:arial;font-size:25px;font-weight:bold;display: flex; align-items: center; justify-content: center; text-align: center;");
myelement.innerHTML = mymsg;
setTimeout(function(){
myelement.parentNode.removeChild(myelement);
},mymsecs);
document.body.appendChild(myelement);
}