抓取错误之onerror

一处定义,可以抓取全局的错误,相当于一个全局的try catch呀。

<html>
<head>
<script type="text/javascript">
onerror=handleErr


function handleErr(msg,url,l)
{
var txt=""
txt="本页中存在错误。

"
txt+="错误:" + msg + "
"
txt+="URL: " + url + "
"
txt+="行:" + l + "

"
txt+="点击“确定”继续。

"
alert(txt)
return true
}

function message()
{
adddlert("Welcome guest!")
}
</script>
</head>

<body>
<input type="button" value="查看消息" onclick="message()" />
</body>

</html>

  

原文地址:https://www.cnblogs.com/williamwsj/p/6700373.html