Merge pull request #305 from RDCH106/master

Added save dialog to example 4
This commit is contained in:
Jos de Jong 2016-06-06 21:09:18 +02:00
commit 45be754de8
1 changed files with 14 additions and 1 deletions

View File

@ -52,8 +52,21 @@
// Save a JSON document
document.getElementById('saveDocument').onclick = function () {
// Save Dialog
fname = window.prompt("Save as...");
// Check json extension in file name
if(fname.indexOf(".")==-1){
fname = fname + ".json";
}else{
if(fname.split('.').pop().toLowerCase() == "json"){
// Nothing to do
}else{
fname = fname.split('.')[0] + ".json";
}
}
var blob = new Blob([editor.getText()], {type: 'application/json;charset=utf-8'});
saveAs(blob, 'document.json');
saveAs(blob, fname);
};
</script>
</body>