思路很簡單,就是利用Blob、URL.createObjectURL()方法和<a> 便籤的HTML5新屬性download來模擬遠端文件下載保存。下面直接上代碼
savePath: function(){ var me = this; if(!me.curve){ $.uitools.alertDlg("Path還沒有定義,請先定義路徑!"); return; } var json = me.pathToJson(); var blob = new Blob([json]); var url = URL.createObjectURL(blob); var a = document.createElement("a"); a.setAttribute('download','path.json'); a.setAttribute('href',url); document.body.appendChild(a); a.click(); a.remove(); },