onerror Event

  
Fires when an error occurs during object loading.
Syntax
Inline HTML
<ELEMENT onerror = "handler" ... >
All platforms
Event property
object.onerror = handler
JScript only
object.onerror = GetRef("handler")
Visual Basic Scripting Edition (VBScript) 5.0 or later only
Named script
<SCRIPT FOR = object EVENT = onerror>
Internet Explorer only
Event Information
Bubbles
No
Cancels
Yes
To invoke
Cause one of the following errors to occur:
  • Run-time script error, such as an invalid object reference or security violation.
  • Error while downloading an object, such as an image.
Default action
Displays the browser error message when a problem occurs and executes any error handling routine associated with the event.
Event Object Properties
Although event handlers in the DHTML Object Model do not receive parameters directly, a handler can query an event object for data.
Show Available Properties
Sets or retrieves a value that indicates the state of the ALT key.
Sets or retrieves a value that indicates the state of the left ALT key.
Sets or retrieves the state of the left CTRL key.
Sets or retrieves the return value from the event.
Retrieves the state of the left SHIFT key.
Sets or retrieves the object that fired the event.
Sets or retrieves the event name from the event object.
Remarks
To suppress the default Microsoft® Internet Explorer error message for the window event, set the returnValue property of the event object to true or simply return true in Microsoft JScript®.
The onerror event fires for run-time errors, but not for compilation errors. In addition, error dialog boxes raised by script debuggers are not suppressed by returning true. To turn off script debuggers, disable script debugging in Internet Explorer by choosing Internet Options from the Tools menu. Click the Advanced tab and select the appropriate check box(es).
Examples
The following examples use the onerror event to handle run-time script errors and object load errors.
This example specifies an invalid script entry. The script in the text field is evaluated when the Throw Error button is clicked. The onerror event fires because the script is invalid. The error results are inserted at the bottom of the sample page instead of in a dialog box.
HideExample
<SCRIPT>
window.οnerrοr=fnErrorTrap;
function fnErrorTrap(sMsg,sUrl,sLine){
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 false;
}
function fnThrow(){
eval(oErrorCode.value);
}
</SCRIPT>
<INPUT TYPE="text" ID=oErrorCode VALUE="someObject.someProperty=true;">
<INPUT TYPE="button" VALUE="Throw Error" οnclick="fnThrow()">
<P>
<DIV ID="oErrorLog">
</DIV>
Show Me
This example shows how to set the handler for the onerror event in script before an image source is specified. When the invalid source is set on the img element, the event fires.
HideExample
<SCRIPT>
var sImg='<IMG STYLE="display: none;" ID=oStub ALT="Default Text">';
function fnLoadFirst(){
oContainer.innerHTML=sImg;
oStub.οnerrοr=fnLoadFail1;
oStub.src="";
oStub.style.display="block";
}
function fnLoadFail1(){
oStub.alt="Image failed to load.";
return true;
}
</SCRIPT>
<INPUT TYPE=button VALUE="Load First Image" οnclick="fnLoadFirst()">
<DIV ID=oContainer></DIV>
Show Me
Standards Information
There is no public standard that applies to this event.
Applies To
OBJECT
Platform
Version
Win16:
4.0
Win32:
4.0
Windows CE:
4.0
Unix:
4.0
Mac:
4.0
Version data is listed when the mouse hovers over a link, or the link has focus.
Move the mouse pointer over an element in the Applies To list to display availability information for the listed platforms.
See Also
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

fanhgye

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值