1function download(filename, text) {
2 var element = document.createElement('a');
3 element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
4 element.setAttribute('download', filename);
5
6 element.style.display = 'none';
7 document.body.appendChild(element);
8
9 element.click();
10
11 document.body.removeChild(element);
12}
13
14// Start file download.
15download("hello.txt","This is the content of my file :)");
16
1function download(link) {
2 var element = document.createElement('a');
3 element.setAttribute('href', link);
4
5 element.style.display = 'none';
6 document.body.appendChild(element);
7
8 element.click();
9
10 document.body.removeChild(element);
11}
1const fs = require('fs');
2const https = require('https');
3
4// URL of the image
5const url = 'GFG.jpeg';
6
7https.get(url,(res) => {
8 // Image will be stored at this path
9 const path = `${__dirname}/files/img.jpeg`;
10 const filePath = fs.createWriteStream(path);
11 res.pipe(filePath);
12 filePath.on('finish',() => {
13 filePath.close();
14 console.log('Download Completed');
15 })
16})
1$('a#someID').attr({target: '_blank',
2 href : 'http://localhost/directory/file.pdf'});
1<iframe id="download_iframe" style="display:none;"></iframe>
2<script>
3 document.getElementById('download_iframe').src = "/example/example.txt";
4</script>
5
6