1

I'm new to JS, so please be patient.

I have this alert pop-up window and I would like to write a piece of code that clicks the OK button inside it whenever it comes up. How can I do it?

Here's my code:

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Alert</h2>

<button onclick="myFunction()">Try it</button>

<script>
function myFunction() {
alert("I am an alert box!");
}
</script>

</body>
</html>
  • 2
    I doubt you can. An `alert()` is specifically to alert the user, and it's a blocking operation until the user dismisses the dialog. What exactly are you trying to accomplish and why? – David Aug 01 '19 at 11:20
  • This is not possible, because the alert box is a widget from browser manufactors. And this support only customised text. You have to create a modal popup for you own. – Reporter Aug 01 '19 at 11:21
  • https://stackoverflow.com/questions/15466802/how-can-i-auto-hide-alert-box-after-it-showing-it you try this article to create your own alert box that can be controlled by js – Tuhin Das Aug 01 '19 at 11:22
  • Well, my question stems from a completely different problem regarding an RPA project. Basically this pop-up comes up in some cases and we would like to run a piece of JS code that can click OK on it. Remember I'm talking about a robot that faces this kind of window (and for some reasons cannot identify it sometimes). – tothakos999 Aug 01 '19 at 11:41

0 Answers0