1
,
Window.onerror
Events
The OnError event is used to assist in processing 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 an error message:
。
If you do not want the browser to display an error message 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, respectively:
1 message: A string that declares information about the error that occurred (a slight difference in the content of the messages returned in different browsers).
2 URL: A string that declares the URL of the document in which the error occurred.
3 lines: A number that declares the line number of the line of code where the error occurred.
For example:
Ps: This method was tested in safari and opera without passing
Note: The onerror event should be bound before other JS programs.
2 , img Load Error
tag supports onerror handle. The event handle is triggered when an image file is not successfully loaded for a variety of reasons. This method allows you to display the default picture when the current picture fails to load.
For example:
When the network reason or other reason, causes the onerror inside to provide the picture address to be not able to load, the IE will loop executes the OnError event, causes the stack overflow, at this time the page will pop up the alert message box, the error message is: "StackOverflow at line:0".
IE 6.0 typically reports an overflow in a pop-up message box and continues to perform its function. However, there are also some overflow vulnerabilities that will close all open windows without prompting. So when you choose to use this event, you should be cautious!
Note The OnError method for: labels has no additional parameters.