Skip to content

Instantly share code, notes, and snippets.

@avelino
Created May 7, 2017 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avelino/b1cff0c5f38539062490cf76aab7fea6 to your computer and use it in GitHub Desktop.
Save avelino/b1cff0c5f38539062490cf76aab7fea6 to your computer and use it in GitHub Desktop.
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