window.onerror事件用来自定义错误处理
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 interfaceErrorEvent
is fired atwindow
andwindow.onerror()
is invoked (as well as handlers attached bywindow.addEventListener
(not only capturing)). - When a resource (such as an
<img>
or<script>
) fails to load, anerror
event using interfaceEvent
is fired at the element that initiated the load, and theonerror()
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 capturingwindow.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.addEventListener
handlers).
window.onerror
window.onerror = function(message, source, lineno, colno, error) { ... }
Function parameters:
message
: error message (string). Available asevent
(sic!) in HTMLonerror=""
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
: Error 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事件用来自定义错误处理的更多相关文章
- 基于window.onerror事件 建立前端错误日志
QA不是万能的,用户的浏览环境非常复杂,很多情况无法靠测试用例去覆盖,所以最好建立一个前端错误日志,在真实用户端收集bug. try&catch是一个捕获前端错误的常见方法,比如: { //给 ...
- [译]window.onerror事件
本文翻译youtube上的up主kudvenkat的javascript tutorial播放单 源地址在此: https://www.youtube.com/watch?v=PMsVM7rjupU& ...
- window.onerror 应用实例
详见: http://blog.yemou.net/article/query/info/tytfjhfascvhzxcytp75 window.onerror = function(sMessa ...
- onerror事件捕获网页中的错误
转载请注明来源:https://www.cnblogs.com/hookjc/ <html><head><script type="text/javascrip ...
- window.onerror 错误监听,发到后台
var doc = document.body || document.documentElement; var _onerror = Onerror(''); var Onerror = funct ...
- img的onerror事件
使用场景 其实on error使用上是比较简单的. 当我们网站上出现了无效图片,而我们希望用友好的方式告诉用户,而不是显示红叉叉. w3c上解释的 定义和用法: onerror 事件会在文档或图像加载 ...
- firefox的window.onerror没有详细的出错提示
当在firefox浏览器的a.htm页面中使用script标签加载某a.js出错时,如果放置window.onerror事件处理方法时,此方法获取到的错误信息都是固定的: {0:"Scrip ...
- window onerror 各浏览器下表现总结
window onerror 各浏览器下表现总结 做前端错误上报,必然离不开window onerror,但window onerror在不同设备上表现并不一致,浏览器为避免信息泄露,在一些情况下并不 ...
- img的onerror事件(瑕疵+解决办法)【转】
显示图片的时候,为了更好的用户体验,可能会把一些没有图片的内容也用图片样式显示出来,此时我们就要用到IMG的onerror事件了,注意MyEclipse的快捷键alt+/是没有的. < img ...
随机推荐
- Linux下目录的权限详解
在Linux文件系统模型中,每个文件都有一组9个权限位用来控制谁能够读写和执行该文件的内容.普通文件大家都了解,这里说说目录的情况. 对于目录来说,执行位的作用是控制能否进入或者通过该目录,而不是控制 ...
- [ CodeVS冲杯之路 ] P1014
不充钱,你怎么AC? 题目:http://codevs.cn/problem/1014/ 一道不用考虑价值的DP题,那么我们可以用 0 和 1 表示是否能够达到该步骤 #include<cstd ...
- [LeetCode] Search for a Range 二分搜索
Given a sorted array of integers, find the starting and ending position of a given target value. You ...
- OpenGL “太阳、地球和月亮”天体运动动画 例子
http://oulehui.blog.163.com/blog/static/7961469820119186616743/ OpenGL “太阳.地球和月亮”天体运动动画 例子 2011-10-1 ...
- 查看 Laravel 的 SQL 语句的方法
在使用 Laravel 的 Eloquent 进行数据查询的时候,很多小伙伴都想看到背后执行的 SQL 语句到底是什么样的,这小笔录就是解决这个小问题的: 在 Providers/AppService ...
- CDH-5.7.0:基于Parcels方式离线安装配置
http://shiyanjun.cn/archives/1728.html https://www.waitig.com/cdh%E5%AE%89%E8%A3%85.html
- 计蒜客 28317.Growling Gears-一元二次方程的顶点公式 (Benelux Algorithm Programming Contest 2014 Final ACM-ICPC Asia Training League 暑假第一阶段第二场 G)
G. Growling Gears 传送门 此题为签到题,直接中学的数学知识点,一元二次方程的顶点公式(-b/2*a,(4*a*c-b*b)/4*a):直接就可以得到结果. 代码: #include& ...
- Educational Codeforces Round 31 B. Japanese Crosswords Strike Back【暴力】
B. Japanese Crosswords Strike Back time limit per test 1 second memory limit per test 256 megabytes ...
- Bug预防体系
Web常见产品问题及预防 测试人员在每次版本迭代中,会对项目的整体质量有一个把控,对于项目常见的问题,开发经常犯的错误都会有所了解,为了避免或者减少这样的错误或不规范的事情在发生,测试人员可以整理构建 ...
- Listener监听器笔记1
1.常用的Web事件监听器接口: 1.ServletContextListener:用于监听Web应用的启动和关闭. 2.ServletContextAttributeListener:用于监听Ser ...