All I want to do is, how can I auto hide alert box within specific seconds after showing it?
All I know is,
setTimeout(function() { alert('close'); }, 5000); // This will appear alert after 5 seconds
No need for this I want to disappear alert after showing it within seconds.
Needed scenario :
Show alert
Hide/terminate alert within 2 seconds
Closing Alerts To close the alert message, add a . alert-dismissible class to the alert container. Then add class="close" and data-dismiss="alert" to a link or a button element (when you click on this the alert box will disappear).
Step 1: Click on the message you want to block. Step 2: Tap the contact's name at the top of the message to open the taskbar. Step 3: Toggle Hide Alerts to the on position.
window. alert() instructs the browser to display a dialog with an optional message, and to wait until the user dismisses the dialog. Under some conditions — for example, when the user switches tabs — the browser may not actually display a dialog, or may not wait for the user to dismiss the dialog.
tldr; 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",5000);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With