1 onerror Event Description
Using the OnError event is an old-fashioned standard method of capturing JavaScript errors in Web pages
2 when to generate OnError events
A onerror event is generated whenever a script error occurs on the page
3 How to use the OnError event
With the OnError event, you must create an incorrect function. You can think of this function as the OnError event handler. This event handler uses three parameters to invoke: Msg (error message), URL (the URL of the page where the error occurred), line (the lines of code where the error occurred)
4 Syntax
OnError = Handleerr
function Handleerr (msg, URL, line) {
Handle the error here
return TRUE or False
}
5 explanation
Whether the browser is a realistic standard error message depends on the return value of the onerror, and if the return value is False, an error message is displayed in the console, or vice versa.
6 Example
<script>
OnError = Handleerr
var txt = "
function Handleerr (msg, URL, line) {
TXT = "There was a" error on the This page. \ n ";
TXT + = ' Error: ' +msg+ ' \ n ';
TXT + = "URL:" +url+ "\ n";
TXT + = "line:" +line+ "\ n";
TXT + = "Click OK to continue.\n\n"
return True
}
Function message () {
Addlert ("Welcome guest!")
}
</scrip>
<body>
<input type= "button" value= "View message" onclick= "message ()" >
</body>
JavaScript onerror Events