JavaScript onerror Events

Source: Internet
Author: User

1 onerror Event Description

Using the OnError event is an old-fashioned standard method of capturing JavaScript errors in Web pages

2 when to generate OnError events

A onerror event is generated whenever a script error occurs on the page

3 How to use the OnError event

With the OnError event, you must create an incorrect function. You can think of this function as the OnError event handler. This event handler uses three parameters to invoke: Msg (error message), URL (the URL of the page where the error occurred), line (the lines of code where the error occurred)

4 Syntax

OnError = Handleerr

function Handleerr (msg, URL, line) {

Handle the error here

return TRUE or False

}

5 explanation

Whether the browser is a realistic standard error message depends on the return value of the onerror, and if the return value is False, an error message is displayed in the console, or vice versa.

6 Example

<script>

OnError = Handleerr

var txt = "

function Handleerr (msg, URL, line) {

TXT = "There was a" error on the This page. \ n ";

TXT + = ' Error: ' +msg+ ' \ n ';

TXT + = "URL:" +url+ "\ n";

TXT + = "line:" +line+ "\ n";

TXT + = "Click OK to continue.\n\n"

return True

}

Function message () {

Addlert ("Welcome guest!")

}

</scrip>

<body>

<input type= "button" value= "View message" onclick= "message ()" >

</body>

JavaScript onerror Events

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.