Creating an URL from a string is very easy with the Blob
constructor and URL.createObjectURL
:
var content = 'some string';
var url = URL.createObjectURL(new Blob([content], { type: 'text/plain' }));
If you're using AJAX, then you don't need to do a string-to-blob conversion. Just set responseType = 'blob';
directly:
var x = new XMLHttpRequest();
x.open('GET', 'http://example.com/');
x.responseType = 'blob';
x.onload = function() {
var url = URL.createObjectURL(x.response);
// ...
};
x.send();