How to get Javascript error messages - log errors to file ?

How can I get Javascript error messages to see where is the problem, so I can correct it quickly ? Is it possible to turn on the logging of Javascript errors into file in the similar way like in case of PHP or SQL errors ?
20 Nov 2021 at 06:06 PM
0pnshow more
LarsLars
Hi,

The difference between Javascript and PHP is that Javascript is a client-side scripting language and PHP is a server-side scripting language, what allows it to easily log error messages into file on server.

Because javascript is running on client side it is difficult to get error messages and save them into file. When a javascript error occurs, it usually stops the script execution, so you can see that some features on website are not working as expected.

Simple way how to see javascript errors is to open a Console in a web browser and run the script or reload the website.

Another option how to find an error is to use alert() function.

These two options are suitable when you are trying to find a javascript error using your PC. But when you need to get an error, that occurs on website visitor's side, you can try to create a script, that will check its running and when there will be an error, it will use Ajax, which allows to log errors to file on server.
21 Nov 2021 at 07:12 PM
0pnshow more
TimTim
Share on FacebookShare on TwitterShare on LinkedInSend email
Follow us on Facebook & Twitter
2021 AnswerTabsTermsContact us