Created
May 7, 2017 19:34
-
-
Save avelino/b1cff0c5f38539062490cf76aab7fea6 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 test(){ | |
console.log("123") | |
settings = { any_kind_of_object: true }; | |
json_str = JSON.stringify(settings); | |
saveFile('yourfilename.json', "data:application/json", new Blob([json_str],{type:""})); | |
} | |
function saveFile (name, type, data) { | |
if (data != null && navigator.msSaveBlob) | |
return navigator.msSaveBlob(new Blob([data], { type: type }), name); | |
var a = $("<a style='display: none;'/>"); | |
var url = window.URL.createObjectURL(new Blob([data], {type: type})); | |
a.attr("href", url); | |
a.attr("download", name); | |
$("body").append(a); | |
a[0].click(); | |
setTimeout(function(){ // fixes firefox html removal bug | |
window.URL.revokeObjectURL(url); | |
a.remove(); | |
}, 500); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment