Answer the question
In order to leave comments, you need to log in
Problem with Blob encoding in Safari?
There is such an initial version of the code for downloading a text file (text/plain) to the OS (a piece of code is taken out from the angular component\typescript):
...
getTextCompanyInfo(): string {
let copyText = '';
this.clientInfo.forEach((field: IInfo) => {
const description = field.description
? `${field.description}: `
: '';
copyText += `${description}${field.value}\n`;
});
return copyText;
}
download(): void {
StatusTrackerModalComponent.createDownloadLink(
this.getTextCompanyInfo()
)
}
static createDownloadLink(
fileBody: string,
fileName: string = 'Реквизиты.txt'
): void {
if (window.navigator && window.navigator.msSaveOrOpenBlob) { // если браузер IE11
window.navigator.msSaveOrOpenBlob(new Blob([fileBody]), fileName);
} else { // если evergreen браузеры
const link = window.document.createElement('a');
link.href = window.URL.createObjectURL(
new Blob([fileBody], { type: 'text/plain;charset=utf-8' })
);
link.download = fileName;
link.click();
}
}
...
import { saveAs } from 'file-saver';
...
getTextCompanyInfo(): string {
let copyText = '';
this.clientInfo.forEach((field: IInfo) => {
const description = field.description
? `${field.description}: `
: '';
copyText += `${description}${field.value}\n`;
});
return copyText;
}
copy(): void {
const copiedText = this.getTextCompanyInfo();
copy(copiedText);
}
download(): void {
const type = 'text/plain;charset=utf-8';
const copiedText = this.getTextCompanyInfo();
const blob = new Blob([copiedText], { type });
saveAs(blob, this.fileName);
}
...
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question