自己处理脚本错误 |
|
当脚本出现运行时错误时,window.onerror事件就会发生。
定义window.onerror可以自己处理这些错误 例子一:让自己试试用window.onerror <html> <script> function window.onerror(msg,file,line) { document.body.innerHTML+="msg :"+msg+"<br>file:"+file+"<br>line:"+line+"<br>"; } </script> <body>List Of Error:<br></body> <script> dsfhsdf </script> <script> document.aaa(); </script> <script> var t="ss"; document.body.insertAdjacentElement("BeforeEnd",t); </script> </html> 例子二: 把错误提交到自定义的程序: <html> <script> function window.onerror(m,f,l) { open( escape("/errorhandle/script_error.php?m="+m+"&f="+f+"&l="+l) ); } </script> ... ... ... |