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. Lettcode Kth Largest Element in an Array

    Lettcode Kth Largest Element in an Array 题意:在无序数组中,寻找第k大的数字,注意这里考虑是重复的. 一直只会简单的O(nlogn)的做法,听说这题有O(n) ...

  2. UOJ356 【JOI2017春季合宿】Port Facility

    暴力就是O(n^2)连边,二分图,这样只有22分. 我们考虑优化建边,我们按照左端点排序,对于一个新加进来的线段,我们向左端点距其最近的和他相交的线段连边,别的相交的我们连同色边,当一个点连了两条同色 ...

  3. codeforces ~ 1004 C Sonya and Robots (dp)

    C. Sonya and Robots time limit per test 1 second memory limit per test 256 megabytes input standard ...

  4. navicat for mysql 2003错误

    最近又一次碰到navicat for mysql 2003错误,之前碰到好几次了,问题再次出现还是有些不知所措,所以记下来,再次遇到时就可以迎韧有余了. 解决方案1: 重启防火墙:关闭再重新开启. 解 ...

  5. Change hostname and IP on Soalris10

    To see the existing configuration: # ifconfig -a Update the following files for IP Address: /etc/hos ...

  6. College student reflects on getting started in open source(一)

    I just completed the first semester of my second year in college, and I'm reflecting on what I learn ...

  7. javascript jquery document.ready window.onload

    网易 博客 下载LOFTER客户端 注册登录  加关注 凡图的编程之路 2012年7月从一个编程新手的点点滴滴 首页 日志 LOFTER 相册 博友 关于我     日志       关于我 Holy ...

  8. loj 数列分块入门 5 7 8

    5 题意 给出一个长为\(n\)的数列,以及\(n\)个操作,操作涉及区间开方,区间求和. 思路 用\(tag\)记录这一块是否已全为\(1\). 除分块外,还可用 树状数组+并查集(链表) 或者 线 ...

  9. 【原创】Linux环境下的图形系统和AMD R600显卡编程(11)——R600指令集

    1 低级着色语言tgsi OpenGL程序使用GLSL语言对可编程图形处理器进行编程,GLSL语言(以下高级着色语言就是指GLSL)是语法类似C的高级语言,在GLSL规范中,GLSL语言被先翻译成教低 ...

  10. Fastjson.tojsonString中$ref对象重复引用问题

    import java.util.ArrayList; import java.util.List; import com.alibaba.fastjson.JSON; import com.alib ...