Using The JavaScript "onerror" Event

 

This script uses the "onerror" event to catch any JavaScript errors, which may have occurred on a page.

In the example below, I use an error in the message function. As you can see below I have inserted the following:

notalert("Welcome to www.wizzardweb.co.uk!")

What I should have done is:

alert("Welcome to www.wizzardweb.co.uk!")

Thus the error message is displayed using the "onerror" event..

If you decide you want to use or alter this script to suit your needs, please give your support and leave a link to this site thanks.

 

Example

 

 

 

Script Source

 

<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 message_alert()
{
notalert("Welcome to www.wizzardweb.co.uk!")
}

// Script by www.wizzardweb.co.uk
</script>

 

 

Please let me know if this script was helpful to you.

[rating]