Onerror event in Java script

Onerror event in Java script

We can detect java script errors by using the following handleErr function. This function will give the error message, url and line number. so that we can easily troubleshoot that error.

Example :

<html>

<head>

<script type=”text/javascript”>

onerror=handleErr

var txt=”"

function handleErr(msg,url,l)

{

txt=”There was an error on this page.\n\n”

txt+=”Error: ” + msg + “\n”

txt+=”URL: ” + url + “\n”

txt+=”Line: ” + l + “\n\n”

txt+=”Click OK to continue.\n\n”

alert(txt)

return true

}

function callfn()

{

adddlert(”Welcome user”)

}

</script>

</head>

<body>

<input type=”button” value=”View alert” onclick=”callfn()” />

</body>

</html>

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.