var documentURLs = ["maca.pdf", "maca2.pdf"]
function printDocuments(index){
if(index > documentURLs.length){
return;
}
else {
printJS({
printable: documentURLs[index],
type: 'pdf',
onPrintDialogClose: function () {
console.log(index);
printDocuments(index++)
}
})
}
}
<button type="button" onclick="printDocuments(0)">Print</button>
This is not incrementing the index, always print first document and it is not stopping
It behaves exactly as it should. If you want to call
printDocumentswith the next index, you should useprintDocument(++index)or justprintDocument(index+1), because it's the least confusing one.i++returns current value ofiand then adds 1.++ifirst adds 1 and returns that increased value (soi+1).