PhotoSwipe 404 prevention with fallback image

164 views Asked by At

I'm displaying some images from Instagram in a PhotoSwipe gallery. The problem is that if the image gets deleted from Instagram, I get 404s in the gallery.

How can I check if the image results in 404 and if so, display a locally saved image (as a fallback)?

1

There are 1 answers

0
krisrak On

You can use the onerror attribute of <img> tag

 <img src="http://www.somewebsite.com/image.png" width=640 height=640 onerror="this.src='/default.png'" />

if image.png does not exist, then default.png is loaded