Created
September 6, 2018 11:09
-
-
Save dotsonjb14/2d77cf0ff7a68b581916bd6e927cd2a3 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
<!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