Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
67
rated 0 times [  71] [ 4]  / answers: 1 / hits: 39700  / 11 Years ago, thu, september 26, 2013, 12:00:00

Is there any way to close a javascript alert() automatically?



I have an alert



alert(Error found);


I want to close it after a few second. Is that possible or shall I go for jQuery dialogue


More From » jquery

 Answers
9

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);

[#75419] Wednesday, September 25, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dylondaytond

Total Points: 92
Total Questions: 88
Total Answers: 96

Location: China
Member since Fri, Jan 15, 2021
3 Years ago
dylondaytond questions
Tue, Jun 22, 21, 00:00, 3 Years ago
Thu, May 7, 20, 00:00, 4 Years ago
;