Created
October 25, 2018 20:54
-
-
Save alexfinnarn/30cbfbfa6a3cb42eef6beba8d35b62a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function downloadFile(finalData) { | |
const data = new Blob([JSON.stringify(finalData, null, 2)], {type : 'application/json'}); | |
if (navigator.msSaveBlob) { | |
// IE 10+. | |
navigator.msSaveBlob(data, 'directory.json'); | |
} else { | |
const link = document.createElement('a'); | |
if (link.download !== undefined) { | |
// Feature detection for Browsers that support HTML5 download attribute. | |
const url = URL.createObjectURL(data); | |
link.setAttribute('href', url); | |
link.setAttribute('download', 'directory.json'); | |
link.style.visibility = 'hidden'; | |
document.body.appendChild(link); | |
link.click(); | |
document.body.removeChild(link); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment