Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript: Detect when an alert box is OK'ed and/or closed

How can I detect when a javascript alert box is OK'ed and/or closed?

like image 383
oshirowanen Avatar asked Aug 22 '11 10:08

oshirowanen


People also ask

How do I handle alert OK button?

Selenium has multiple APIs to handle alerts with an Alert interface. To click on the Ok button on alert, first of all we have to switch to alert with switchTo(). alert() method. Next, to click on the Ok button, we have to use accept() method.

What happens when JavaScript runs the alert () function?

One useful function that's native to JavaScript is the alert() function. This function will display text in a dialog box that pops up on the screen. Before this function can work, we must first call the showAlert() function. JavaScript functions are called in response to events.

Can you style alert box JavaScript?

The standard alert box in JavaScript does not provide the option to apply CSS. To style your alert box, you need to create a custom one first. The custom alert box will be created using jQuery and styles will be applied to CSS.

What is alert prompt and confirm in JavaScript?

prompt. shows a message asking the user to input text. It returns the text or, if Cancel button or Esc is clicked, null . confirm. shows a message and waits for the user to press “OK” or “Cancel”.


1 Answers

Since alert is blocking:

alert('foo'); function_to_call_when_oked_or_closed(); 

Just put the function after the call to alert.

like image 51
Quentin Avatar answered Oct 11 '22 22:10

Quentin