Im trying to achieve the same goal as OP there: Downloading mp3 files using html5 blobs in a chrome-extension but not the him's code, not the solution offered in discussion does not work for my google-chrome 19.0.1084.46. Im working in chrome-console on the local (file://) page, and errors for this code:
finalUrl = "http://cs1076.userapi.com/u3040678/audio/d7ff6874cfa4.mp3";
var xhr = new XMLHttpRequest();
xhr.open("GET", finalURL, true);
xhr.setRequestHeader('Content-Type', 'octet-stream');
xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
xhr.onreadystatechange = function()
{
if(xhr.readyState == 4 && xhr.status == 200)
{
var bb = new (window.BlobBuilder || window.WebKitBlobBuilder)();
bb.append(xhr.responseText);
var blob = bb.getBlob("application/octet-stream");
var saveas = document.createElement("iframe");
saveas.style.display = "none";
saveas.src = window.webkitURL.createObjectURL(blob);
document.body.appendChild(saveas);
delete xhr;
delete blob;
delete bb;
}
}
xhr.send();
looks like
OPTIONS http://cs1076.userapi.com/u3040678/audio/d7ff6874cfa4.mp3 405 (Not Allowed) cs1076.userapi.com/u3040678/audio/d7ff6874cfa4.mp3:1 XMLHttpRequest cannot load http://cs1076.userapi.com/u3040678/audio/d7ff6874cfa4.mp3. Origin null is not allowed by Access-Control-Allow-Origin.
And the second subquestion: in according to How can i generate a file and offer it for download in plain javascript? - is the creation of iframe the best way to offer file to download?