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

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')

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

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

												

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. 洛谷 P2485 [SDOI2011]计算器 解题报告

    P2485 [SDOI2011]计算器 题目描述 你被要求设计一个计算器完成以下三项任务: 1.给定y.z.p,计算y^z mod p 的值: 2.给定y.z.p,计算满足xy ≡z(mod p)的最 ...

  2. mac 安装 visual studio 配置

    前言:今天主要分享的是 Mac 下一款编程软件--Visual Studio,的确,这款软件之前一直是只有 Windows 系统独占的,2017年终于开发了 Mac 版本. 微软这次为 Mac 开发者 ...

  3. WPF的webBrowser控件关键代码

    1.根据元素ID获取元素的值. 比如要获取<img class="" id="regimg" src="/register/checkregco ...

  4. (二十三)深入了解epoll (转)

    一. 介绍Epoll 是一种高效的管理socket的模型,相对于select和poll来说具有更高的效率和易用性.传统的select以及poll的效率会因为 socket数量的线形递增而导致呈二次乃至 ...

  5. python登陆github

    #!/usr/bin/env python # encoding: utf-8 import requests from headers import headers from lxml import ...

  6. mysql 共享空间转为独立表空间

    由于以前的mysql配置为共享表空间,服务器空间不足,清理日志表里的数据后,数据库并没缩小,照成空间浪费,现在修改为独立表空间 #独立表空间innodb_file_per_table=1 #停止事物日 ...

  7. Selenium2+python自动化15-select下拉框【转载】

    前言最近由于工作原因,更新慢了一点,今天终于抽出一点时间给大家继续更新selenium系列,学习的脚本不能停止,希望小伙伴能多多支持. 本篇以百度设置下拉选项框为案例,详细介绍select下拉框相关的 ...

  8. poj 1375(解析几何)

    Intervals Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4292   Accepted: 1288 Descrip ...

  9. 忘记MySQL数据库密码的解决办法

    在windows下: 打开命令行窗口,停止MySQL服务: Net stop MySQL 启动mysql,一般到mysql的安装路径,找到 mysqld-nt.exe (或mysqld.exe) 执行 ...

  10. react setState里的作用域

    从接触racet开始,我们就认识了setState,它是对全局变量进去更新的一个重要方法, 不仅可以更新数据,还能在更新后执行方法时直接调用刚刚更新的数据 今天碰到的问题就在于它的作用域的先后问题 先 ...