onerror 事件

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script>
  5. onerror = handleErr;
  6. var txt = "";
  7. function handleErr(msg, url, l) {
  8. txt = "此页面出错。\n\n";
  9. txt += "错误:" + msg + "\n";
  10. txt += "URL:" + url + "\n";
  11. txt += "Line:" + l + "\n\n";
  12. txt += "单击“确定”以继续。\n\n";
  13. alert(txt);
  14. return true;
  15. }
  16.  
  17. function message() {
  18. adddlert("欢迎访客!");
  19. }
  20. </script>
  21. </head>
  22.  
  23. <body>
  24. <input type="button" value="查看消息" onclick="message()" />
  25. </body>
  26.  
  27. </html>