window.onerror is used to catch and supress the script error. but it
will catch the error only when the script is within the same source
file.
for example, consider a html file MainFrame.htm as,
<IFRAME src="ScriptError.jsp" id="controllerFrame"
name="controllerFrame" height=150 width="450"
APPLICATION="yes"></IFRAME>
<BR>
<DIV id=oErrorLog style="border:1px groove orange
;width:450px;height:200px; "></DIv>
<SCRIPT>
var frm=document.frames;
window.onerror=fnErrorTrap;
oErrorLog.innerHTML=frm(1).name;
function fnErrorTrap(sMsg,sUrl,sLine){
alert("err");
oErrorLog.innerHTML="<b>An error was thrown and caught. </b><p>";
oErrorLog.innerHTML+="Error: " + sMsg + "<br>";
oErrorLog.innerHTML+="Line: " + sLine + "<br>";
oErrorLog.innerHTML+="URL: " + sUrl + "<br>";
return true;
}
</SCRIPT>
ScriptError.jsp is as:
<BODY>
<INPUT TYPE="text" ID=oErrorCode VALUE="someObject.someProperty=true;">
<script>
document.write(eval(oErrorCode.value));
</script>
</BODY>
in the script of MainFrame.htm, frm(1) is null object and the error is
catched and suppressed, but the file scriptError.jsp also has the
script errror. what i need is to catch the error in scriptError.jsp
also from the MainFrame.htm, is it possible to catch the error?