[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 865
  • Last Modified:

Javascript img onFailure (reverse of onLoad)?

Is there a way to execute javascript when an image fails to load (ie 404, request timed out or 403 etc.....).
Simply, I have a few images, and some do not load and for these images I want to switch the src to something different (instead of the ALT text displaying).

Is this possible?

Thanks
0
petemod
Asked:
petemod
1 Solution
 
GwynforWebCommented:
try this

<img src="http://abc.com/DontExist.jpg" onError="alert('Image did not load')">
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now