利用window.onerror可以实现当脚本出错时的自定义信息:
<script type="text/javascript">
window.onerror=function(msg, url, line){
alert("An error has occurred\r\n" + msg + "\r\n" + url + "\r\n" + line);
return true;
}
</script>
<script type="text/javascript">
// Syntax error
document.write('hi there'
</script>
截图:
