The answer depends on whether or not you have control of the iframe code, and whether or not it is the same domain.
If same domain then you can do the following to set the error handling function from the wrapping document:
document.getElementById("myiframe").contentWindow.onerror=function() {
alert('error!!');
return false;
}
make sure you wait for the iframe to finish loading before setting the error handler.
If it's not the same domain but you have control of the iframe content (both domains are under your control), you can communicate with the outer frame by using a cross domain communication framework (google it or build it yourself), i.e. catch the error in the iframe by setting the onerror handler from within the iframe and send it through the framework to the outer document.
If it's not the same domain and you don't have control of the iframe, there's no way for the outer document to know what's going on inside it because of security constraints.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…