Skip to content Skip to sidebar Skip to footer

How Can I Revoke An Object Url Only After It's Downloaded?

I'm saving a file in JavaScript using the following code: var a = document.createElement('a'); a.href = URL.createObjectURL(new Blob(['SOME DATA'])); a.download = 'some.dat'; a.cli

Solution 1:

a.click() on a DOM element simulates a click on the element, instead of propagation of the click event, so it's directly sent to the browser. I believe it would be a little bit safer to move revoking of URL object to another event cycle using a timer:

setTimeout(function() {
 URL.revokeObjectURL(a.href);
}, 0);

Post a Comment for "How Can I Revoke An Object Url Only After It's Downloaded?"