The JavaScript onerror method is the first thing to handle error in JavaScript. This error event is called on the window object whenever any exception occurs on the page.
There are three pieces of information to identify the exact error:
Example of JavaScript onerror:
<html>
<head>
<script type="text/javascript">
window.onerror = function (msg, url, line) {
console.log("Message : " + msg );
console.log("url : " + url );
console.log("Line number : " + line );
}
</script>
</head>
<body>
<p>Click the following button:</p>
<form>
<input type="button" value="Click Here" >
Read Also: JavaScript Strict mode
Alternatively, you can use an onerror method to display an error message if there is any problem in loading an image.
<img src="image.jpg" onerror="alert('Loading failed')" /> Are you an owner of a small business who’s trying to come up with ways…
Introduction When patients bring me their lab reports, the confusion is almost always the same.…
Are you excited about remodeling your house after a long time? Perhaps if you're planning…
The practice of yoga teaches us to be present, patient and mindful of our decisions.…
As we are once again allowed to go outside, nearly everyone is planning to go…
How do you find a cleaning company that will take excellent care of your business…