script.onload, onerror
script.onload / script.onerror
Important:
Events onload
/onerror
track only the loading itself.
Errors that may occur during script processing and execution are out of scope for these events. That is: if a script loaded successfully, then onload
triggers, even if it has programming errors in it. To track script errors, one can use window.onerror
global handler.
Other resources
The load
and error
events also work for other resources, basically for any resource that has an external src
.
For example:
let img = document.createElement('img');
img.src = "https://js.cx/clipart/train.gif"; // (*)
img.onload = function() {
alert(`Image loaded, size ${img.width}x${img.height}`);
};
img.onerror = function() {
alert("Error occurred while loading image");
};
There are some notes though:
- Most resources start loading when they are added to the document. But
<img>
is an exception. It starts loading when it gets a src(*)
. - For
<iframe>
, theiframe.onload
event triggers when the iframe loading finished, both for successful load and in case of an error.
Author And Source
이 문제에 관하여(script.onload, onerror), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@hqillz/script.onload-onerror저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)