博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
window.onerror事件用来自定义错误处理
阅读量:5955 次
发布时间:2019-06-19

本文共 1513 字,大约阅读时间需要 5 分钟。

Event reference:      

 

原文: 

An  for the  event. Error events are fired at various targets for different kinds of errors:

  • When a JavaScript runtime error (including syntax errors and exceptions thrown within handlers) occurs, an  event using interface  is fired at  and window.onerror() is invoked (as well as handlers attached by  (not only capturing)).
  • When a resource (such as an  or ) fails to load, an  event using interface  is fired at the element that initiated the load, and the onerror() handler on the element is invoked. These error events do not bubble up to window, but (at least in Firefox) can be handled with a single capturing .

Installing a global error event handler is useful for automated collection of error reports.

Syntax

For historical reasons, different arguments are passed to window.onerror and element.onerror handlers (as well as on error-type handlers).

window.onerror

window.onerror = function(message, source, lineno, colno, error) { ... }

Function parameters:

  • message: error message (string). Available as event (sic!) in HTML onerror=""handler.
  • source: URL of the script where the error was raised (string)
  • lineno: Line number where error was raised (number)
  • colno: Column number for the line where the error occurred (number)
  • error:  (object)

When the function returns true, this prevents the firing of the default event handler.

window.addEventListener('error')

window.addEventListener('error', function(event) { ... })

event of type  contains all the information about the event and the error.

 

 

 

 

转载地址:http://hhexx.baihongyu.com/

你可能感兴趣的文章
音乐播放器
查看>>
CodeForces 722C Destroying Array
查看>>
HTML 图片加载问题
查看>>
HTML
查看>>
Nginx配置详解
查看>>
python常见的数据结构
查看>>
powerDesigner
查看>>
黑马程序员—文件读取路径及行读取的方式,今晚总算有点小懂
查看>>
自己用的一套reset.css,打算整理一下方便以后用,持续更新中,各位大神,不喜勿喷...
查看>>
DBA_实践指南系列7_Oracle Erp R12监控OAM(案例)
查看>>
【HASH】【UVA 10125】 Sumset
查看>>
常用的Javascript设计模式
查看>>
[ACM] poj 2249 Binomial Showdown (排列组合公式优化)
查看>>
java9学习之模块化
查看>>
深入理解正则表达式
查看>>
C#_LINQ(LINQ to Entities)
查看>>
数据库主键与外键
查看>>
tidb 架构 ~Tidb学习系列(5)
查看>>
DOM
查看>>
Android ADB 常用命令
查看>>