How to download a text using js

Basha - Mar 29 '23 - - Dev Community

Hello:)
You can easily download a custom text using js.

function Download(){
    var name = "file name"

    const content = "text";
    const element = document.createElement('a');
    const blob= new Blob([content], {
        type:'plain/text'
    });
    const fileurl = URL.createObjectURL(blob);
    element.setAttribute('href', fileurl);
    element.setAttribute('download', name+".html");
    element.style.display = 'none';
    document.body.appendChild(element);
    element.click();

    document.body.removeChild(element);
}
Enter fullscreen mode Exit fullscreen mode

This function will download a file as a text file

. . . . . . . . . . . . . . . . . .
Terabox Video Player