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')" />Based on United States, Jacob Frazier is a skilled JavaScript developer with over 8 years of experience. He is passionate about change and trying new things, both professionally and personally. He loves startups and is extremely proactive.
Introduction The influence of words is more significant than ever in a digital age. Whether…
The success of any tech innovation depends on its share in various industries and business…
Facing Google penalties can be a daunting challenge for businesses relying on organic search traffic.…
Technology, undeniably, has made our lives easier. But the advent of artificial intelligence has been…
Guest post services have become an essential tool for businesses and individuals looking to increase…
Programming continues to evolve at a rapid pace, with new trends and technologies emerging every…