如果扩展名为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") {
}
}
答案 0 :(得分:2)
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));
}
}