current position:Home>JavaScript create Download

JavaScript create Download

2022-05-15 02:05:55thankseveryday

/** *  Generate downloads  * @param {string} fileName  file name  * @param {string} fileType  File suffix  * @param {string} content  The contents of the document  */
makeDownload(fileName, fileType, content) {
    
    var pom = document.createElement('a');
    pom.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(content));
    pom.setAttribute('download', `${
      fileName}.${
      fileType}`);
    if (document.createEvent) {
    
        var event = document.createEvent('MouseEvents');
        event.initEvent('click', true, true);
        pom.dispatchEvent(event);
    } else {
    
        pom.click();
    }
}

copyright notice
author[thankseveryday],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/132/202205120527258968.html

Random recommended