📄 js_onerror.asp@output=print
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>JavaScript onerror Event</title>
<link rel="shortcut icon" href="../favicon.ico" type="image/x-icon" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta name="Keywords" content="xml,tutorial,html,dhtml,css,xsl,xhtml,javascript,asp,ado,vbscript,dom,sql,colors,soap,php,authoring,programming,training,learning,beginner's guide,primer,lessons,school,howto,reference,examples,samples,source code,tags,demos,tips,links,FAQ,tag list,forms,frames,color table,w3c,cascading style sheets,active server pages,dynamic html,internet,database,development,Web building,Webmaster,html guide" />
<meta name="Description" content="Free HTML XHTML CSS JavaScript DHTML XML DOM XSL XSLT RSS AJAX ASP ADO PHP SQL tutorials, references, examples for web building." />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "../../https@ssl./default.htm" : "../../www./default.htm");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-3855518-1");
pageTracker._initData();
pageTracker._trackPageview();
</script>
</head>
<body>
<p>From <b>http://www.w3schools.com</b> (Copyright Refsnes Data)</p>
<h1>JavaScript The onerror Event</h1>
<a href="js_throw.asp"><img alt="previous" border="0" src="../images/btn_previous.gif" width="100" height="20" /></a>
<a href="js_special_characters.asp"><img alt="next" border="0" src="../images/btn_next.gif" width="100" height="20" /></a>
<hr />
<p class="intro">Using the onerror event is the old standard solution to catch errors in a web page.</p>
<hr />
<h2>Examples</h2>
<p><a target="_blank" href="tryit.asp@filename=tryjs_onerror">The onerror event
(an example with an error)</a><br />
How to use the onerror event to catch errors in a web page.</p>
<hr />
<h2>The onerror Event</h2>
<p>We have just explained how to use the try...catch
statement to catch errors in a web page. Now we are going to explain how to use
the onerror event for the same purpose.</p>
<p>The onerror event is fired whenever there is a script error in the page.</p>
<p>To use the onerror event, you must create a function to handle the errors.
Then you call the function with the onerror event handler. The event handler is called with three arguments: msg (error message), url (the url of the page that caused the error) and line (the line
where the error occurred).</p>
<h3>Syntax</h3>
<table class="ex" cellspacing="0" border="1" width="100%">
<tr>
<td>
<pre>onerror=handleErr</pre>
<pre>function handleErr(msg,url,l)
{
//Handle the error here
return true or false
}</pre>
</td>
</tr>
</table>
<p>The value returned by onerror determines whether the browser displays a
standard error message. If you return false, the browser displays the standard
error message in the JavaScript console. If you return true, the browser does not display
the
standard error message.</p>
<h3>Example</h3>
<p>The following example shows how to catch the error with the onerror event:</p>
<table class="ex" cellspacing="0" border="1" width="100%" id="table1">
<tr>
<td>
<pre><html>
<head>
<script type="text/javascript">
onerror=handleErr;
var txt="";</pre>
<pre>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;
}</pre>
<pre>function message()
{
adddlert("Welcome guest!");
}
</script>
</head></pre>
<pre><body>
<input type="button" value="View message" onclick="message()" />
</body></pre>
<pre></html></pre>
</td>
</tr>
</table>
<br />
<hr />
<a href="js_throw.asp"><img alt="previous" border="0" src="../images/btn_previous.gif" width="100" height="20" /></a>
<a href="js_special_characters.asp"><img alt="next" border="0" src="../images/btn_next.gif" width="100" height="20" /></a>
<p>From <b>http://www.w3schools.com</b> (Copyright Refsnes Data)</p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -