Я хочу загрузить несколько изображений в моем коде.Я передал отдельные URL-адреса для загрузки, и одиночное изображение загружается, но когда я беру URL-адреса изображения в массив, они не загружаются.Вот мой код:
<script type="text/javascript">
//var upics = ["https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ0cq-7TkAONUjnDKz2AkEgiFRG6E0Dmrl43lOuj_nQCOrnQG8","https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ0cq-7TkAONUjnDKz2AkEgiFRG6E0Dmrl43lOuj_nQCOrnQG8"];
var _OBJECT_URL;
document.querySelector('#download-button').addEventListener('click', function() {
var upics = ["https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQGvEiBfvtvDFi2aSNDydoH_DVaCJBtaaIpl0PhrddPdx4cwoAX","https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ0cq-7TkAONUjnDKz2AkEgiFRG6E0Dmrl43lOuj_nQCOrnQG8"];
for (index = 0; index < upics.length; index++) {
console.log("hiii");
var request = new XMLHttpRequest();
request.addEventListener('readystatechange', function(e) {
/* if(request.readyState == 2 && request.status == 200) {
document.querySelector('#start-download').style.display = 'block';
document.querySelector('#download-button').style.display = 'none';
}
else if(request.readyState == 3) {
document.querySelector('#download-progress-container').style.display = 'block';
document.querySelector('#start-download').style.display = 'none';
} */
if(request.readyState == 4) {
_OBJECT_URL = URL.createObjectURL(request.response);
document.querySelector('#save-file').setAttribute('href', _OBJECT_URL);
document.querySelector('#save-file').setAttribute('download', 'images.jpeg');
/* document.querySelector('#save-file').setAttribute('download', [upics]); */
document.querySelector('#save-file').style.display = 'block';
document.querySelector('#download-progress-container').style.display = 'none';
/* setTimeout(function() {
window.URL.revokeObjectURL(_OBJECT_URL);
document.querySelector('#download-button').style.display = 'block';
document.querySelector('#save-file').style.display = 'none';
}, 60*1000); */
}
});
/* request.addEventListener('progress', function(e) {
var percent_complete = (e.loaded / e.total)*100;
document.querySelector('#download-progress').style.width = percent_complete + '%';
}); */
request.responseType = 'blob';
console.log("imageis"+upics[index]);
/* request.open('get',[upics]); */
//request.open('get', 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ0cq-7TkAONUjnDKz2AkEgiFRG6E0Dmrl43lOuj_nQCOrnQG8');
request.open('get',upics[index]);
request.send();
}
});
</script>