如何找出由于找不到资源而未加载的所有元素?
<body>
<img src="notThere.png">
<script src="notInHere.png"></script>
<img src="DoesExist.png">
// want to find the first and the script with unexisting sources, but not the second image with an existing source.
</body>
有人可以给我一个提示如何找出这些元素吗?我认为,onerror
为每个元素设置不是解决方案,因为元素可能是动态加载的。
不幸的是,window.onerror
不会因“找不到资源”错误而触发。
例子:
<body>
<script src="someonesScript.js"></script> <!-- this script might load images/audio etc.. -->
<script>
// now put here whatever you like
// but find out which resources (images,scripts,..) were tried to load (from the script above)
// and can't be loaded
</script>
</body>
希望这个例子有助于理解我的问题。