Event reference:      https://developer.mozilla.org/en-US/docs/Web/Events

http://w3c.github.io/html/webappapis.html#events

原文: https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onerror

An event handler for the error 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 error event using interface ErrorEvent is fired at window and window.onerror() is invoked (as well as handlers attached by window.addEventListener (not only capturing)).
  • When a resource (such as an <img> or <script>fails to load, an error event using interface Event 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 window.addEventListener.

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 window.addEventListenerhandlers).

window.onerror

  1. 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)
  • errorError Object (object)

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

window.addEventListener('error')

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

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

  1.  

window.onerror事件用来自定义错误处理的更多相关文章

  1. 基于window.onerror事件 建立前端错误日志

    QA不是万能的,用户的浏览环境非常复杂,很多情况无法靠测试用例去覆盖,所以最好建立一个前端错误日志,在真实用户端收集bug. try&catch是一个捕获前端错误的常见方法,比如: { //给 ...

  2. [译]window.onerror事件

    本文翻译youtube上的up主kudvenkat的javascript tutorial播放单 源地址在此: https://www.youtube.com/watch?v=PMsVM7rjupU& ...

  3. window.onerror 应用实例

    详见: http://blog.yemou.net/article/query/info/tytfjhfascvhzxcytp75   window.onerror = function(sMessa ...

  4. onerror事件捕获网页中的错误

    转载请注明来源:https://www.cnblogs.com/hookjc/ <html><head><script type="text/javascrip ...

  5. window.onerror 错误监听,发到后台

    var doc = document.body || document.documentElement; var _onerror = Onerror(''); var Onerror = funct ...

  6. img的onerror事件

    使用场景 其实on error使用上是比较简单的. 当我们网站上出现了无效图片,而我们希望用友好的方式告诉用户,而不是显示红叉叉. w3c上解释的 定义和用法: onerror 事件会在文档或图像加载 ...

  7. firefox的window.onerror没有详细的出错提示

    当在firefox浏览器的a.htm页面中使用script标签加载某a.js出错时,如果放置window.onerror事件处理方法时,此方法获取到的错误信息都是固定的: {0:"Scrip ...

  8. window onerror 各浏览器下表现总结

    window onerror 各浏览器下表现总结 做前端错误上报,必然离不开window onerror,但window onerror在不同设备上表现并不一致,浏览器为避免信息泄露,在一些情况下并不 ...

  9. img的onerror事件(瑕疵+解决办法)【转】

    显示图片的时候,为了更好的用户体验,可能会把一些没有图片的内容也用图片样式显示出来,此时我们就要用到IMG的onerror事件了,注意MyEclipse的快捷键alt+/是没有的. < img ...

随机推荐

  1. SQL触发器(AFTER和INSTEAD OF)

    转自:http://www.cnblogs.com/shepherldeng/archive/2010/06/23/1763766.html 何为触发器:触发器是数据库服务器中发生事件时自动执行的特种 ...

  2. 每天一个小算法(insertion sort3)

    今天多看看插入排序的理论部分. 先贴几个概念吧: 1.伪代码(英语:pseudocode),又称为虚拟代码,是高层次描述算法的一种方法.它不是一种现实存在的编程语言(已经出现了类似伪代码的语言,参见N ...

  3. Socket学习进阶之基础通信

    服务端代码: using System; using System.Text; using System.Net; using System.Net.Sockets; public class ser ...

  4. Xcode5 上64位编译 出错No architectures to compile for

    http://blog.csdn.net/chocolateloveme/article/details/16900999 详细错误信息如下: No architectures to compile ...

  5. 双缓冲(Double Buffer)原理和使用【转】

    转自:http://blog.csdn.net/acs713/article/details/16359551 原文出自:http://blog.csdn.net/xiaohui_hubei/arti ...

  6. UVA 10081 Tight numbers(POJ 2537)

    直接看代码就OK.思路比较简单.就是注意概率要在转移过程中算出来.不能算成成立的方案书除以总方案数(POJ的这道题可以这么干.数据很水么.另外POJ要用%.5f,%.5lf 会WA.) #includ ...

  7. aiohttp/asyncio测试代理是否可用

    #!/usr/bin/env python # encoding: utf-8 from proxyPool.db import RedisClient import asyncio import a ...

  8. 【一】ODB - C++ 访问数据库的利器--Hello World On Windows(Version-24)

    本文以MySQL数据库为例,其他数据类似. 官方文档和下载 ODB官方首页    官方开发者说明书(开发教程) 安装下载首页(下载与安装教程Windows/Linux) Windows安装步骤(都是英 ...

  9. python的位运算

    # &: 都是1,才为1,否则为零 # |: 都是0,才为0,否则为1 # ^: 相同为0,相异为1 a = bin(20) b = bin(16) print(a) # 0b10100 pr ...

  10. ectouch 微信支付成功后订单状态未改变的解决办法 (转载)

    原文地址: 微信支付支付成功后,返回到mobile/wx_native_callback.php 之前代码 define('IN_ECS', true); require(dirname(__FILE ...