So, basically, I need to detect whether an alert window was thrown. I
can't find where it's thrown from but I need to disable a button only
if there were no alert windows thrown. Any ideas?
Presumably, you are the one calling alerts so surely you can do this
some other way? Anyhow, all you do is assign a reference to
window.alert to some other global variable, then assign your own
function to window.alert - you *must* do this in the right order or
you'll lose your one and only reference to the window.alert function.
Disable the button by default, then enable it with your replacement
alert function. Of course users without JavaScript won't be able to
enable the button, but then they can't call alerts either.
e.g.
<script type="text/javascript">
// Function to run when alert called
function trapAlert(msg){
document.getElementById('aButton').disabled = false;
xAlert(msg);
}
// Assign reference to window.alert to another variable
var xAlert = window.alert;
// Re-assign window.alert
window.alert = trapAlert;
</script>
<input type="button" value="Button to enable" id="aButton" disabled
onclick="alert('I\'m working!!');">
<input type="button" value="Call an alert" onclick="alert('hey');">