I would like to download certain object stored in state (React) by clicking button that is present in DOM. Thing is I want to avoid creating extra DOM element and force clicking it (not sure if it's possible tho).
By clicking button I am launching class method where e (event) is an argument. Inside this methodI have created new Blob object with two arguments:
var blob = new Blob([JSON.stringify([...this.state.data])], { type: "application/json" })
//also tried text/json
then I assigned referrer and download properties as below:
e.target.href = URL.createObjectURL(blob)
e.target.download = "data.json"
Console says everything seems to be all way set:
Blob { size: 495, type: "application/json" } blob:http://localhost:3000/aa517a7b-2e7d-46a8-8949-c8946947ff51 data.json
But the above doesn't work, download action is not getting triggered. Does it mean I need to 'click' blob link once more? If so, then how can I perform this if I already have triggered click event by clicking 'Download JSON' button? Note that I don't want to create another DOM element.
I tried it on both Chrome and FF and got the same result.