onerror事件捕获网页中的错误

转载请注明来源:https://www.cnblogs.com/hookjc/

<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 message()
{
adddlert("Welcome guest!")
}
</script>
</head>
<body>
<input type="button" value="View message" onclick="message()" />
</body>
</html>

 

注:当点击按钮时出现错误,则触发onerror事件 即onerror=handleErr    去执行handleErr方法,msg为错误信息,url为当前显示的url地址,l表示错误的行号

来源:python脚本自动迁移

posted @ 2020-06-29 11:59  jiangcheng_15  阅读(344)  评论(0编辑  收藏  举报