Skip to content

Instantly share code, notes, and snippets.

@kyeljmd
Last active February 17, 2017 06:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyeljmd/e577ed5b58d8d70855a9b0bfff6cc398 to your computer and use it in GitHub Desktop.
Save kyeljmd/e577ed5b58d8d70855a9b0bfff6cc398 to your computer and use it in GitHub Desktop.
(function() {
var isCorsEnabled = function(tag) {
var corsEnabled;
var target = $(tag)[0];
var currentSrcUrl = target.src.split("_t=").join("_t=1"); // add a leading 1 to the ts
$.ajax({
url: currentSrcUrl,
async: false
})
.done(function() {
// things worked out, we can add the CORS attribute and reset the source
target.crossOrigin = "anonymous";
target.src = currentSrcUrl;
corsEnabled = true;
})
.fail(function() {
corsEnabled = false;
});
return corsEnabled;
}
window.isCorsEnabled = isCorsEnabled
}())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment