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?
The best bet to solve your problems with annoying JavaScript would be to override it with a client side scripting tool like Greasemonkey.
I'm pretty sure it's not possible.
What happens if you override alert with a no-op in your code?
e.g.
With the line commented out, alert appears. With line commented in, alert does not appear.
I highly doubt it. If by separate domain, do you mean one which you have no control over?
If you do have control, you could change the alerts to modal Javascript boxes, which you could control.
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 :)
You shouldn't have a problem if you know the text of the alert and don't mind getting dirty.
You can override the iframe window's alert with your own and do something to the effect of..
Edit: I made a little test with a proxy handler (it's in asp.net/c# but you should get the idea)...
The external page in my test is a w3 page with a button that displays an alert, the alert is now passed through the user defined function.
I'm sure this is alot more dirty then you'd like to get.
Page:
Proxy Handler: