Is it possible to check if a file returns a 404 error if it's on a different server using jQuery/javascript?
I'm using the youtube api to get a HD screenshot for the video I'm embedding, but the JSON that it returns gives no indication of whether a HD screenshot for the video exists.
the url for the screenshot is usually, http://img.youtube.com/vi/ + video.ID + /maxresdefault.jpg
but when it doesn't exist, i get this ugly low-res gray POS: http://img.youtube.com/vi/MAyTES9gDAU/maxresdefault.jpg
So, basically, I want to check if the screenshot exists and if not, apply display: none
to the div that holds it.
Create an <img>
element pointing to that image, then handle the onerror
event and hide it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With