외부파일 로드 중 img 태그에 이미지가 로드가 안될 때
1. 대체이미지로 변경
onerror="" 사용
대체이미지마저 없을 경우를 대비해서 null을 넣어준다.
<img src="image.png" alt="이미지" onerror="this.onerror=null;this.src='image_none.png'">
2. display: none
<img src="image.png" alt="이미지" onerror="this.style.display='none'">
참고
https://www.w3schools.com/jsref/event_onerror.asp
onerror Event
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
www.w3schools.com
728x90
'Web > javascript' 카테고리의 다른 글
[자바스크립트] Optional Chaining 연산자(?.) (0) | 2023.01.18 |
---|---|
[자바스크립트] axios (0) | 2022.12.30 |
[자바스크립트] 제어 구문 (0) | 2022.01.25 |
[자바스크립트] scrollY vs pageYOffset 무엇을 써야하나? (0) | 2021.03.19 |
[자바스크립트] 원시타입 참조타입 (0) | 2021.03.10 |