JS 由前端保存到文件
Posted 413xiaol
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JS 由前端保存到文件相关的知识,希望对你有一定的参考价值。
function doSave(value, type, name) var blob; if (typeof window.Blob == "function") blob = new Blob([value], type: type); else var BlobBuilder = window.BlobBuilder || window.MozBlobBuilder || window.WebKitBlobBuilder || window.MSBlobBuilder; var bb = new BlobBuilder(); bb.append(value); blob = bb.getBlob(type); var URL = window.URL || window.webkitURL; var bloburl = URL.createObjectURL(blob); var anchor = document.createElement("a"); if (‘download‘ in anchor) anchor.style.visibility = "hidden"; anchor.href = bloburl; anchor.download = name; document.body.appendChild(anchor); var evt = document.createEvent("MouseEvents"); evt.initEvent("click", true, true); anchor.dispatchEvent(evt); document.body.removeChild(anchor); else if (navigator.msSaveBlob) navigator.msSaveBlob(blob, name); else location.href = bloburl; var test = a: [1, 2], b: [3, 4] doSave(JSON.stringify(test), "text/latex", "hello.txt");
以上是关于JS 由前端保存到文件的主要内容,如果未能解决你的问题,请参考以下文章
js 上传文件,通过django存储到数据库,保存类型为blob类型