English 中文(简体)
Base64 URL生成的编码/编码和下载内容
原标题:Base64 encode/decode and download content generated in URL

我正在通过 JavaScript 生成字符串, 我需要下载到带有预定义的动态文件名的文本文件。 这样就不会有员工出错的空间 。

这在JavaScript显然是不可能的,因为安全问题。 然而,从我所读到的,应该可以使用基本64编码。

我设法用解码数据编码字符串并打开一个 URL 。 字符串已在此 URL 中成功解码。 格式如下:

var data =  data:text/plain;base64, +L_EncodedData;
document.location = data;

我需要用解码数据打开一个文件对话框, 这样员工就可以下载此 URL 中生成的内容 。

有帮助吗?

事先多多谢感谢

问题回答

如果您仍然在寻找答案, 请看看< a href=" https:// stackoverflow. com/ questions/ 9707604/output- a- pdf- in- php- from- a- byte- array/ 1635099# 16350999" 我在这里的回答 。 这就是我如何根据您的需要调整它 。

// Convert the Base64 string back to text.
var txt = atob(data.reportBase64Bytes);

// Blob for saving.
var blob = new Blob([byteString], { type: "text/plain" });

// Tell the browser to save as report.txt.
saveAs(blob, "report.txt");

如果您使用这个, 一定要抓住我在另一篇文章中提到的多填充物 。

此块已固定 。

window.OpenWindowForBase64 = function(url, callback) {
    var image = new Image();
    image.src = url;
    var w = window.open("");
    w.document.write(image.outerHTML);
    if (callback) {
        callback(url);
    }
}




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签