<button type="button" onclick="do_dl();">Test downloading 3 text files.</button>
<script>
SP.SOD.executeFunc('sp.js', 'SP.ClientContext');
var siteurl="https://****.sharepoint.com/sites/DEV/";
function GetDocuments(success,failure) {
debugger;
$.ajax({
url: siteurl + "/_api/web/lists/getbytitle('Documents')/items?$select=EncodedAbsUrl&$expand=File",
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
success(data.d.results);
},
error: function (data) {
debugger;
failure(data);
}
});
}
function GetDocumentsSuccess(arrayname)
{
debugger;
alert("Success");
download_files([
{ download: arrayname[0].EncodedAbsUrl, filename: arrayname[0].File.Name},
{ download: arrayname[1].EncodedAbsUrl, filename: arrayname[1].File.Name},
{ download: arrayname[2].EncodedAbsUrl, filename: arrayname[2].File.Name},
{ download: arrayname[3].EncodedAbsUrl, filename: arrayname[2].File.Name},
{ download: arrayname[4].EncodedAbsUrl, filename: arrayname[2].File.Name},
{ download: arrayname[5].EncodedAbsUrl, filename: arrayname[2].File.Name},
]);
}
function GetDocumentsFailure()
{
alert("Failure");
}
function download_files(files) {
debugger;
function download_next(i) {
debugger;
if (i >= files.length) {
return;
}
var a = document.createElement('a');
a.href = files[i].download;
a.target = '_parent';
// Use a.download if available, it prevents plugins from opening.
if ('download' in a) {
a.download = files[i].filename;
}
// Add a to the doc for click to work.
(document.body || document.documentElement).appendChild(a);
if (a.click) {
a.click(); // The click method is supported by most browsers.
} else {
$(a).click(); // Backup using jquery
}
// Delete the temporary link.
a.parentNode.removeChild(a);
// Download the next file with a small timeout. The timeout is necessary
// for IE, which will otherwise only download the first file.
setTimeout(function() {
download_next(i + 1);
}, 500);
}
// Initiate the first download.
download_next(0);
}
</script>
<script>
SP.SOD.executeFunc('sp.js', 'SP.ClientContext');
var siteurl="https://****.sharepoint.com/sites/DEV/";
function GetDocuments(success,failure) {
debugger;
$.ajax({
url: siteurl + "/_api/web/lists/getbytitle('Documents')/items?$select=EncodedAbsUrl&$expand=File",
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
success(data.d.results);
},
error: function (data) {
debugger;
failure(data);
}
});
}
function GetDocumentsSuccess(arrayname)
{
debugger;
alert("Success");
download_files([
{ download: arrayname[0].EncodedAbsUrl, filename: arrayname[0].File.Name},
{ download: arrayname[1].EncodedAbsUrl, filename: arrayname[1].File.Name},
{ download: arrayname[2].EncodedAbsUrl, filename: arrayname[2].File.Name},
{ download: arrayname[3].EncodedAbsUrl, filename: arrayname[2].File.Name},
{ download: arrayname[4].EncodedAbsUrl, filename: arrayname[2].File.Name},
{ download: arrayname[5].EncodedAbsUrl, filename: arrayname[2].File.Name},
]);
}
function GetDocumentsFailure()
{
alert("Failure");
}
function download_files(files) {
debugger;
function download_next(i) {
debugger;
if (i >= files.length) {
return;
}
var a = document.createElement('a');
a.href = files[i].download;
a.target = '_parent';
// Use a.download if available, it prevents plugins from opening.
if ('download' in a) {
a.download = files[i].filename;
}
// Add a to the doc for click to work.
(document.body || document.documentElement).appendChild(a);
if (a.click) {
a.click(); // The click method is supported by most browsers.
} else {
$(a).click(); // Backup using jquery
}
// Delete the temporary link.
a.parentNode.removeChild(a);
// Download the next file with a small timeout. The timeout is necessary
// for IE, which will otherwise only download the first file.
setTimeout(function() {
download_next(i + 1);
}, 500);
}
// Initiate the first download.
download_next(0);
}
</script>