I'm guessing nope, but you never know.
<img src="http://example.net/lolcat.png">
lolcat.png
to http://static.example.net/bandwidth-exceeded.gif
Can I detect this?
Cross-browser isn't important, just looking for an option that will work in any 1 popular browser.
So far my best option is knowing the size of the placeholder image, getting a "maybe" by looking at the image size onload (in browsers that support onload events in image tags), and making a quick XHR request notifying the backend that we've got a maybe.
A JavaScript redirect is a piece of JavaScript code that is used to automatically transfer a visitor from a landing page to a different target page.
Definition and Usage The required src attribute specifies the URL of an image. Note: The src property can be changed at any time. However, the new image inherits the height and width attributes of the original image, if not new height and width properties are specified.
In JavaScript, page redirection is simple. The window object's location object is a property. A web page can be redirected in a number of ways.
I checked with the following code:
var a=new Image(); a.src='http://example.com/image.png';
alert( a.width );
which in this case returns 0 since the image doesn't exist.
On link text I found quite a few properties that might be worth checking out. And if that fails you might want to look into jQuery and AJAX.
Edit:
tested on firefox firebug
var a=new Image();
a.src='http://l.yimg.com/g/images/photo_unavailable_m.gif';
console.log(a.width); // the image exists and returns 240
var b=new Image();
b.src='http://farm3.static.flickr.com/2560/4098180849_729ef4f6ef_m.jpg';
console.log(b.width); // the image does not exist (re-direct) and returns 0
the answer to your question Can Javascript be used to detect a redirected image SRC (in any popular browser)? is simple as you said , nope! because http doesnt have any option for identifying the redirection. This is similar to detecting url redirection, which is simply a limitation for javascript.
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