聘我网

新概念招聘3.0

自定义Javascript出错信息

vote up0vote downstar

利用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>

截图:

alt text

 

您的回答





不是您要找的问题? 浏览其他含有标签 的问题或者 自己问个.