Skip to content

Instantly share code, notes, and snippets.

@dotsonjb14
Created September 6, 2018 11:09
Show Gist options
  • Save dotsonjb14/2d77cf0ff7a68b581916bd6e927cd2a3 to your computer and use it in GitHub Desktop.
Save dotsonjb14/2d77cf0ff7a68b581916bd6e927cd2a3 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script>
let file = new Blob(['{"Message": "Hello"}']);
let fileName = "myFileName.json";
if (window.navigator.msSaveOrOpenBlob) {
// IE specific download.
navigator.msSaveBlob(file, fileName);
}
else {
let dler = document.createElement('a');
let file = window.URL.createObjectURL(file)
dler.href = file;
dler.download = fileName;
document.body.appendChild(dler)
dler.click();
document.body.removeChild(dler);
window.URL.revokeObjectURL(file);
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment