Home > Web Front-end > CSS Tutorial > How Can I Hide the \'Image Not Found\' Icon in My Web Browser?

How Can I Hide the \'Image Not Found\' Icon in My Web Browser?

Patricia Arquette
Release: 2024-12-01 18:39:15
Original
317 people have browsed it

How Can I Hide the

Hiding "Image Not Found" Icon

When an image file cannot be located, browsers typically display a generic "Image not found" icon in its place. To avoid this unsightly default behavior, there are techniques to silently hide this icon.

Using Inline JavaScript

One effective method involves using the onerror event listener. By attaching this listener to the image, you can specify an action to perform when the image fails to load. For instance:

<img onerror='this.style.display = "none"' src="image.png">
Copy after login

When the image at "image.png" is not found, the onerror event handler will set the display property of the image to "none." This effectively hides the image, even though it technically remains present in the code.

The above is the detailed content of How Can I Hide the \'Image Not Found\' Icon in My Web Browser?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template