需求:導出瀏覽器工作臺的日志,導出成txt文件;
const filename = '臨時日志';
const qhyhLog = 'abcdefg'; // 需要導出的字符串
const element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(qhyhLog));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);