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. busybox根文件系统使用记录

    1.DHCP功能配置 1.1.配置Linux内核使能DHCP相关选项: [*]Networking support --> Networking support Networking optio ...

  2. 使AD域控服务器Administrator的密码永不过期方法。

    在安装完AD域后,管理员密码会42天就要更新一次,这样对测试比较不方便, 如果要让域控管理员账号密码永远不过期,就照着下面的方法执行: open a Command Prompt as the adm ...

  3. 【马克-to-win】—— 学习笔记

    声明 以下学习内容转载自:http://www.mark-to-win.com/ 社区,由马克java社区创始人---"马克-to-win"一人全部独立写作,创作和制作. 非常感谢 ...

  4. Java面试题之hashmap中用什么hash算法解决碰撞的?

    查了一下源码(jdk8),记录一下吧,能记住就记一下吧! static final int hash(Object key) { int h; return (key == null) ? 0 : ( ...

  5. 【转】beyond compare 启动提示“应用程序发生错误”

    [转]beyond compare 启动提示“应用程序发生错误”   今天到公司BCompare不能打开,重新安装也不能打开.最后处理下,就解决了.方法是把C:\Documents and Setti ...

  6. python和shell对比

    python和shell都是我们经常使用的脚本语言,平时python主要用来写一些小型的任务,shell则在使用liunx系统部署任务的时候用的比较多,由于两者有一些相似之处,时间长了容易混掉,所以这 ...

  7. 快速了解Android重要机制

    转自 http://www.jianshu.com/p/5f6d79323923 一.Android系统底层研究 关于底层的知识点不是在一篇文章中能讲解清楚,参见本人的Android底层研究系列,不断 ...

  8. xmlhelper类

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Xm ...

  9. java如何增加数组长度

    遇到一个面试题:在不使用list的add方法的情况下,动态的添加元素(大概是这个样子): ArrayList是基于数组实现的,是一个动态数组,其容量能自动增长,需学习arraylist的相关知识(ht ...

  10. Vue.js 2使用中的难点举例--子组件,slot, 动态组件,事件监听

    一例打尽..:) <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> < ...