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
errorevent using interfaceErrorEventis fired atwindowandwindow.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, anerrorevent using interfaceEventis 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.addEventListenerhandlers).
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 ...
随机推荐
- 8.2 前端检索的敏感词过滤的Python实现(针对元搜索)
对于前端的搜索内容进行控制,比如敏感词过滤,同样使用socket,这里使用Python语言做一个demo.这里不得不感叹一句,socket真是太神奇了,可以跨语言把功能封装,为前端提供服务. 下面就是 ...
- android工程下assets与raw文件夹
在应用的开发中,当我们创建一个新的Android工程后,我们会发现工程中包含了一个目录assets,另外当我们察看一些示例工程的时候,有时会发现在该工程的资源目录下会有一个raw目录(res/raw) ...
- Linux 安装配置JDK
一.下载jdk 参考:http://www.codingyun.com/article/40.html 可以先下载到本地,然后ftp到服务器 也可以直接在服务器下载(windows版本的区分32位与6 ...
- 树形结构JSON的实现方法
在Web应用程序开发领域,基于Ajax技术的JavaScript树形控件已经被广泛使用,它用来在Html页面上展现具有层次结构的数据项.目前市场上常见的JavaScript框架及组件库中均包含自己的树 ...
- centos7配置环境LNMP
#yum安装epel-release第三方软件包 yum install epel-release #要验证EPEL仓库是否建立成功 yum repolist xshell访问系统出现中文乱码的解决方 ...
- for...in与点语法
语法 for...in语句循环一个指定的变量来循环一个对象所有可枚举的属性.如下所示 for (variable in object){ statements } 问题 在实际的使用过程中发现,在fo ...
- malloc,calloc,realloc区别
malloc:memory allocation calloc:The 'c' indicates 'cleared' realloc:The realloc() function changes t ...
- C程序编译过程浅析【转】
转自:http://blog.csdn.net/koudaidai/article/details/8092647 前几天看了<程序员的自我修养——链接.装载与库>中的第二章“编译和链接” ...
- 理解python的super
def super(cls, inst): mro = inst.__class__.mro() return mro[mro.index(cls) + 1] super做了这些事 摘自:https: ...
- 左侧菜单栏右侧内容(改进,有js效果)
(如有错敬请指点,以下是我工作中遇到并且解决的问题)上一篇文章是简洁版 这是上一篇文章的改进. 上一篇文章的左侧菜单是没有子目录的. 这是效果图: 左侧菜单代码: <div class=&quo ...