我无法搞清楚这一点。事实上,我真的不知道从哪里开始。我需要弄清楚我的网站如何制作文件(HTML或文本!!!)然后下载它。有点像Google Docs如何制作您的文档文件,然后您可以下载它。代码需要是HTML和JavaScript。 JQuery也很好。谢谢!
答案 0 :(得分:1)
您应该指定要制作的文件类型。 我制作了一个小片段,展示了如何创建纯文本和二进制文件(在本例中为图像)文件。
var textData = new Blob(['My file content'], {type: 'text/plain'});
var myTextFile = window.URL.createObjectURL(textData);
document.getElementById('downloadText').href = myTextFile;
var base64Data = "iVBORw0KGgoAAAANSUhEUgAAAFAAAABQCAYAAACOEfKtAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QA/wD/AP+gvaeTAAAHm0lEQVR42u2cz4scRRTHv6+qZn8k2QTiz4sYRDwFFLxFMJJ/wEMkOSzZDQRBiB49BMGDB/WgeN3EhNldxIMiQfCa7CqE5KB4yOpBQXJICBKDm5ndzMxOdz0Ps707PV3dXdW/Zkb2wW5mun69+vR7r+pV9wbYkz0ZplCWRueXW5JIntjq6pMMeqYybRng4CPvXn7+sP7jyGHvw7k3ZjqV6bItzgDfXWpPt7qob7T0qS2PM92AzNIPcOcX8OoRgRee5mVm/9yZ12e8KlUSLpWJBDY7+OTfDf905fASFQOkVHNEcnFpZaNW5dBOAN9b3nxis6Pf6XefSiXllkmpZqUSl5dXNyarUskJ4HpLHe16XJlymSYk1ZyQcmGpIohOADueqtQ9ImJh+QRACHlWCHGpCnd2AqiH5boDwhbXpVRzQor64kpTlamLE8Bhi839G4A4K6W8srjaLM2dxwqgjQyuM1KqOSnkwtKPm6VA/N8BNFmpkOqsIHGpvtosPCaOD0A2f+e0esFEpZxTQtWXVouNiWMDkAf+NQkltAMAIeUsCXl5caW4mDg2ANPEdoMgpZoXUi4srjQKgTgeAC3d1xqiUGelVBfr1xq5Y+JYAExzX2ZOrmDojISaF0rV80IcfYAWUDY7OjX+maSXO6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CbneRKaamkrRRqgXE6eBr4/f7uAXpPWUpvbwGYbW5CwXGvX0qOgeY9XOqELSfNNmAy9OMiOSwwftRBhaYngDPHOHJazqY+bd06YdKagaUbAq2t9CZ5/+4vwz7QfcSaBI6/FL8KZ+kzSXwNfH0L6DtLKAUeUPKRvvF5b2gCZSRX8XqEx7avmyS5AdoM2PGAb3+hngv3bUlsD99cOWvujRmnX1HwgIo20p0t4OrPoRcorBR3mqhl7CwSHlDxRtq2al5wcZeLhgdUsJEGeovIay9yahaR9trazb8ovLI6bMTLgAeUuIj0KzY1Abx9XOfKhZmB3+7LHkBHGGXBA6qIgUVK4sGr4brtQyWrArNU8moHM9BoAdLteU2kDz1i8ICKTqQbLeDcopmey5M+KcIvRmbRpUh4QAVvJuwM1Bf/nB6PpqZ/Yf0y8RlOLmwnWR7EZykeBjwg54P1QhaUHNCAjCc9BU7A2QKrgGZTZdjgAil/Fc5wgp1Ynhd+wfsw90ykBEVsusoNrmCdA3G3wAKUyPJ2Q67+CsrRTVLNRjpLmyLAOQ5e+nFW0YNH+ihysiWDC2TouXCh0DIQGdnTmFiFM2hcBrgM1Y1SCsCiHnWMMrhA3FxY+4XBKWRyZVgz+079OR1xdluPupmoWEzKKb5mDMY2TVzn6ASw1bi3xv1/7phRGBmgIUsDt2asvU57/e6aS99OAG9+/spDr9NYsPVjjvnJNPsSwfUqM7rtxsKtL15+6DKGYyqn0W03LrDmZ9XUzCmSE+W9d58z1ro01/4We53mN91O84LrOJkAHHt/TQpZO0FUO0lSFfpfwTuvvBTz2VK07/3Nuvud1t3rtz476raC7MmeDF3+A3Un3Gd/OuALAAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDE1LTA0LTA5VDIxOjQ1OjUzLTA3OjAwXW3BgAAAACV0RVh0ZGF0ZTptb2RpZnkAMjAxNS0wNC0wOVQyMTo0NTo1My0wNzowMCwweTwAAAAASUVORK5CYII=";
var binaryData = atob(base64Data);
var buffer = new ArrayBuffer(binaryData.length);
var byteArray = new Uint8Array(buffer);
for (var i = 0; i < binaryData.length; i++)
byteArray[i] = binaryData.charCodeAt(i);
var imageData = new Blob([byteArray], {type: 'image/png'});
var myImage = window.URL.createObjectURL(imageData);
document.getElementById('downloadImage').href = myImage;
&#13;
<a id="downloadText" download="filename.txt">Download Text File</a><br />
<a id="downloadImage" download="image.png">Download Image</a>
&#13;