when user clicks on a button i want to show a popup alert with some message like "you are redirecting" and after 2 to 3 seconds popup alert needs to close automatically. Is it possible to do this one in javascript ? could any one suggest how to achieve this.
Asked
Active
Viewed 69 times
-3
-
https://stackoverflow.com/questions/15466802/how-can-i-auto-hide-alert-box-after-it-showing-it – Asons May 06 '18 at 10:00
-
Possible duplicate of [Javascript close alert box](https://stackoverflow.com/questions/463368/javascript-close-alert-box) – CertainPerformance May 06 '18 at 10:00
1 Answers
-1
you can use setTimeout
function to achieve this.
document.getElementById('my-btn').onClick = function(e) {
e.preventDefault();
showPopup();
setTimeout(function () {
location.href = 'new location';
}, 2000);
}

Ali Shabani
- 428
- 2
- 10