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 ...
随机推荐
- 刷新iframe
<button onclick="document.getElementById('frame').contentWindow.location.reload(true)"& ...
- 如何禁用Eclipse的Validating
使用Eclipse开发项目,在加载项目.刷新项目.修改了某个代码的时候,经常出现Eclipse正在Validating的提示.项目比较大文件(js)较多的情况下,甚至出现Validating几分钟的盛 ...
- Codeforces Round #356 (Div. 2) C
C. Bear and Prime 100 time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Gradle for Android(三)多渠道打包、配置签名信息
多渠道打包 国内有太多Android App市场,每次发版几十个渠道包.还好Android Gradle给我们提供了productFlavors,我们可以对生成的APK包进行定制. productFl ...
- Js String 属性扩展
String.prototype.startsWith = function (startStr) { var d = startStr.length; return (d >= 0 &am ...
- Nginx整合PHP原理
安装Nginx 在网上,看到不少人装Nginx 时非常麻烦,配置时用了一大堆选项,请问你们真实现那么多功能么?害的我越看越郁闷.此次安装Nginx如果是按着上面笔者的步骤一步步走下来,安 ...
- linux下java.io.IOException: Cannot run program "/opt/jdk/jre/bin/java": error=13, Permission denied
linux下启动jetty时报: [root@mv01 jetty-distribution-9.2.14.v20151106]# java -jar start.jar java.io.IOExce ...
- -webkit-box-flex: 1;属性和 float 属性冲突造成元素看不见的BUG
今天切图的时候发现了这个问题,样式是这样的: .check-btns-box .check-btn{float: left;-webkit-box-flex: 1;-moz-box-flex: 1;- ...
- gitlib 安装
参考文件https://www.cnblogs.com/rslai/p/9109624.html
- 使用windos电脑模拟搭建集群(四)web环境 linux+nginx+jdk+tomcat
1.使用ansible的playbook自动安装两台web主机的nginx 1.配置模块 主机清单 2.创建 playbook目录并编写安装nginx的playbook mkdir -p playbo ...