0

Is there any way to dismiss JavaScript alert() programatically OR by pressing any key and not necessarily pressing the ENTER key?

AndrewL64
  • 15,794
  • 8
  • 47
  • 79

2 Answers2

2

You may try boot box plugin

var alert = bootbox.alert('Count to 5...');
alert.show();
setTimeout(function() { alert.modal('hide'); }, 5000);
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootbox.js/4.4.0/bootbox.min.js"></script>
Peter B
  • 22,460
  • 5
  • 32
  • 69
Antu
  • 2,197
  • 3
  • 25
  • 40
0

Yes, you can use ESC key instead of Enter

Sebastian Kaczmarek
  • 8,120
  • 4
  • 20
  • 38
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - [From Review](/review/low-quality-posts/21550125) – Mustapha Larhrouch Nov 29 '18 at 14:15
  • I must disagree, it does provide an answer to the question. It provides *direct* answer to the question. Let me quote OP: "Is there any way to dismiss [...] alert() programatically *OR* by pressing any key and not necessarily pressing the ENTER key?". And the answer is - yes, you can dismiss `alert()` by pressing any other key than enter - the key is ESC. And this is what I suggested – Sebastian Kaczmarek Dec 01 '18 at 12:37