-3

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.

Maheswar
  • 3
  • 7

1 Answers1

-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