If you are open to using a third-party proxy, you can do this. Obviously not a javascript solution . This uses the proxy service from cors-anywhere.herokuapp.com. Just add this solution for people who are open to proxies and do not want to implement this in the backend.
Here is the fork of the original violin
$.ajaxPrefilter( function (options) { if (options.crossDomain && jQuery.support.cors) { var http = (window.location.protocol === 'http:' ? 'http:' : 'https:'); options.url = http + '//cors-anywhere.herokuapp.com/' + options.url; //options.url = "http://cors.corsproxy.io/url=" + options.url; } }); $.ajax({ type: 'HEAD', //'GET' url:document.getElementById("testImage").src, success: function(data, textStatus, request){ alert(request.getResponseHeader('X-Final-Url')); }, error: function (request, textStatus, errorThrown) { alert(request.getResponseHeader('X-Final-Url')); } });
source share