[英]How to capture client-side missing resources?
I'm trying to capture instances of missing resources by adding the following code snippet to my site's <head>
:我试图通过将以下代码片段添加到我的网站的
<head>
来捕获丢失资源的实例:
window.onerror = function(message, file, line) {
console.log('Error:', message, file, line);
}
But this only seems to capture JS errors, not general DOM errors.但这似乎只捕获 JS 错误,而不是一般的 DOM 错误。 I've tried deliberately: 1) creating
<script>
tags pointing to non-existent files, and 2) creating <img>
tags pointing to non-existent images.我故意尝试过:1)创建指向不存在文件的
<script>
标签,以及 2)创建指向不存在图像的<img>
标签。 Neither triggers an error
event.两者都不会触发
error
事件。
My questions are:我的问题是:
onerror
listening for? onerror
监听什么样的错误?如果您认为某个特定元素可能具有不存在的图像或脚本,并且您通常不需要捕获内容,则可以将onerror
添加到这些特定的img
或script
标签:
<img src="http://something/that/might/not/exist.png" onerror="alert('Error!');">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.