How to listen for any 301/302 redirect status codes on cross-domain image requests?

Viewed 3427

I have a few <img>'s that are linked (with the src attribute) to cross-domain URLS that may need to redirect to some other image URL. I need to somehow track every redirect that takes place when the browser requests the original URL.

So for example, If I have:

<img src='http://www.something.com/redirect'/>

and http://www.something.com/redirect sent a custom location header to http://something.com/pic.jpg, I need to know about it. How could I detect a redirect in JS or jQuery on a <img>?

4 Answers
Related