I have a html-jquery script to download a lot of files.
This files are downloades by calling the event onClick on all those url. They are automatically saved on Download folder. But I would like to rename the files before they are saved on Download dfolder.
How can I do it? This is my code:
<script src=https://code.jquery.com/jquery-3.6.0.min.js
</script>
<script id="funciones">
var count = 0;
function linkGen() {
var requestId =[
['111111111111111111111111111111111111','7373'],
['222222222222222222222222222222222222','8888'],
['333333333333333333333333333333333333','6767'],
['444444444444444444444444444444444444','9999']
]
count = 0;
var html = '';
$.each(requestId, function (item, value) {
var link = 'https://mylink.com/index.php?entryPoint=download&id=' + value[0] + '&type=Note';
count++;
var fileName = value[1] + '_' + getFileNameFromUrl(link);
html += '<div><a href="' + link + '" id="link' + count + '" download="' + fileName + '" onclick="event.preventDefault(); window.open(`' + link + '`, `_blank`);">Link ' + count + '</a></div>';
})
$('div').html(html);
}
function getFileNameFromUrl(url) {
var parts = url.split("/");
return parts[parts.length - 1];
}
linkGen();
link = 0;
function down() {
if (link <= count) {
var enlace = $('#link' + link).attr('href');
$('#link' + link).click();
link++;
console.log(link + ' - ' + enlace);
}
}
function buttonOn() {
setInterval(down, 1000);
}
</script>