如何在新标签页/窗口中编写文本文档?
How to write a text document in new tab / window?
以下代码用于在扩展名为 jpg 的情况下在新选项卡中显示图像。
同样,如果扩展名是txt,我想在新标签中写一个文本文档(从base64字符串到文本)。
success: function (data) {
var extension = fileName.split('.').pop();
if (extension == "jpg") {
var image = new Image();
image.src = "data:image/jpg;base64," + data.d;
var w = window.open("");
w.document.write(image.outerHTML);
}
else if(extension == "txt") {
}
}
Base64 图像更简单,因为您只需将 base64 粘贴到图像源中,其他内容如文本需要解码。参见 https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding
success: function (data) {
var extension = fileName.split('.').pop();
if (extension == "jpg") {
var image = new Image();
image.src = "data:image/jpg;base64," + data.d;
var w = window.open("");
w.document.write(image.outerHTML);
}
else if(extension == "txt") {
var w = window.open("");
w.document.write(window.atob(data.d));
}
}
以下代码用于在扩展名为 jpg 的情况下在新选项卡中显示图像。
同样,如果扩展名是txt,我想在新标签中写一个文本文档(从base64字符串到文本)。
success: function (data) {
var extension = fileName.split('.').pop();
if (extension == "jpg") {
var image = new Image();
image.src = "data:image/jpg;base64," + data.d;
var w = window.open("");
w.document.write(image.outerHTML);
}
else if(extension == "txt") {
}
}
Base64 图像更简单,因为您只需将 base64 粘贴到图像源中,其他内容如文本需要解码。参见 https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding
success: function (data) {
var extension = fileName.split('.').pop();
if (extension == "jpg") {
var image = new Image();
image.src = "data:image/jpg;base64," + data.d;
var w = window.open("");
w.document.write(image.outerHTML);
}
else if(extension == "txt") {
var w = window.open("");
w.document.write(window.atob(data.d));
}
}