Thursday, May 26, 2011

Track Error in Javascript Page


Hi
Many times we have faced problems to find what is javascript errors and exactly where??
To track javascript error, It is a good practice to write code in Try..Catch
but sometimes some small syntax error are not allowing to execute the whole js file.
so to track such error during development, we can track by this sample code
  <script type="text/javascript">
        onerror = CallOnError;
        function CallOnError(msg, url, line) {
            var strErrMessage = "";
            strErrMessage += "Message: " + msg + "\n";
            strErrMessage += "Page: " + url + "\n";
            strErrMessage += "Line Number: " + line + "\n\n";
            alert(strErrMessage);
            return true;
        }
    </script>
  

Here is a sample error

try to put on your page

  <script type="text/javascript">
            alert('This is First Test Page);
    </script>

Enjoy Coding
Post a Comment