Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
28
rated 0 times [  29] [ 1]  / answers: 1 / hits: 16340  / 11 Years ago, fri, september 6, 2013, 12:00:00

I want to disappear the alert box after a certain amount of time. I have heard that this is impossible in Javascript, so is there another way of making this happen?


More From » alert

 Answers
13

Try this jsbin code - A custom alert box for you



http://jsbin.com/ibUrIxu/1/edit



or Try this on your .html file



Code



<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
<script>
function customAlert(msg,duration)
{
var styler = document.createElement(div);
styler.setAttribute(style,border: solid 5px Red;width:auto;height:auto;top:50%;left:40%;background-color:#444;color:Silver);
styler.innerHTML = <h1>+msg+</h1>;
setTimeout(function()
{
styler.parentNode.removeChild(styler);
},duration);
document.body.appendChild(styler);
}
function caller()
{
customAlert(This custom alert box will be closed in 2 seconds,2000);
}
</script>
</head>
<body onload=caller()>

</body>
</html>

[#75858] Thursday, September 5, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
loganl

Total Points: 424
Total Questions: 86
Total Answers: 112

Location: Zimbabwe
Member since Thu, Jul 21, 2022
2 Years ago
;