1
,
Window. onerror
Event
The onerror event is used to help handle JavaScript errors on the page. When an exception occurs on the page, the error event is triggered on the window object. For example:
In this case, the browser displays the error message:
.
If you do not want the browser to Display error messages in the default dialog box, let the onerror method return true.
In addition, the onerror method provides three parameters to determine the exact error information:
1) message: a string that declares the error message (the message content returned in different browsers varies slightly ).
2) url: a string that declares the URL of the document with an error.
3) line: a number that declares the row number of the wrong code line.
For example:
Ps: This method has not passed the test in safari and Opera.
Note: The onerror event should be bound before other js programs.
2,ImgLoading error
labels support onerror handles. This event handle is triggered when an image file fails to be loaded for various reasons. This method can display the default image when loading the current image fails.
For example:
When the image address provided in onerror cannot be loaded due to network or other reasons, ie executes the onerror event cyclically, causing stack overflow. The alert message box is displayed on the page, error message: "stackoverflow at line: 0 ".
IE 6.0 reports overflow in pop-up message boxes and continues to execute its functions. However, some overflow vulnerabilities close all opened windows without any prompts. Therefore, be careful when using this event!
Notes: The onerror method of the label does not have any additional parameters.