how to force download javascript
function downloadFile(data, fileName, type="text/plain") {
// Create an invisible A element
const a = document.createElement("a");
a.style.display = "none";
document.body.appendChild(a);
// Set the HREF to a Blob representation of the data to be downloaded
a.href = window.URL.createObjectURL(
new Blob([data], { type })
);
// Use download attribute to set set desired file name
a.setAttribute("download", fileName);
// Trigger the download by simulating click
a.click();
// Cleanup
window.URL.revokeObjectURL(a.href);
document.body.removeChild(a);
}
Also in JavaScript:
- javascript event bind dynamic element
- three js cdn
- javascript datum addieren
- javascript funtion
- javascript check if variable exists
- remove item jquery
- electron didn't know require
- package json proxy
- fetch response json or text
- javascript tutorial pdf
- iterate over node object children
- make object readonly javascript
- how to append data to a field in mongoose model
- check if time is greater than javascript
- bookshelfjs npm
- javascript get object property with variable
- javascript rpg tutorial
- jquery hide()
- pm2 group console messages
- fetch composition API in Vue3
- angularjs dropdown
- json server paging
- javascript atualize array
- javascript compare arrays