I have a page with an iframe whose source page is in a separate domain. From time to time, the source page generates an alert. When it does so, it stops what it is doing until the user clicks OK to the alert.
What I would like to do is programmatically click OK on this alert so the source page can get back to being useful. Is this possible?
You can create a custom function that'll replace the native alert() box in the user's web browser. You'll do this from the window object, and the custom function will work as such: Set constants for the alert title and alert button text.
blurt is a javascript replacement for default alert(), prompt(), and confirm() functions in javascript. The equivalents in blurt are: alert() -> blurt()
The alert() method in JavaScript is used to display a virtual alert box. It is mostly used to give a warning message to the users. It displays an alert dialog box that consists of some specified message (which is optional) and an OK button. When the dialog box pops up, we have to click "OK" to proceed.
JavaScript is single-threaded, which means when you call a function, it blocks until it returns. When you call alert(), that passes control to the browser which decides how to handle it. It is not Javascript which is popping the UI dialog, it is the browser. alert() does not return until the browser receives the "OK" event and returns control. The javascript thread is halted until that happens.
So for at least two different reasons stated in the above paragraph, the answer is no :)
What happens if you override alert with a no-op in your code?
e.g.
<script>
// uncomment next line to swallow alerts
// function alert(nope) { return; }
<script>
<script>
$(document).ready(function() { alert("Hello, world!"); });
</script>
With the line commented out, alert appears. With line commented in, alert does not appear.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With