icestark
icestark copied to clipboard
<script /> 资源执行错误,仍执行 onLoad 事件
非 icestark 错误,需要考虑下是否要处理这种情况

Demo: index.html
<!DOCTYPE html>
<html>
<body>
<script>
const element = document.createElement('script');
element.src = './index.js'
element.addEventListener(
'error',
() => {
console.log('error----')
},
false,
);
element.addEventListener('load', () => {
console.log('load---')
}, false);
document.getElementsByTagName('head')[0].appendChild(element)
</script>
</body>
</html>
index.js
(function(){
throw new Error('error')
})();