I want to download multi images from website, pls check my javascript and xml code, what's wrong with my code?
And how to insert that javascript into xml?
Here is my javascript code
var zip = new JSZip();
var count = 0;
var zipFilename = "zipFilename.zip";
var urls = [
'http://google.com/image1',
'http://google.com/image2',
'http://google.com/image3'
];
urls.forEach(function(url){
var filename = "filename";
// loading a file and add it in a zip file
JSZipUtils.getBinaryContent(url, function (err, data) {
if(err) {
throw err; // or handle the error
}
zip.file(filename, data, {binary:true});
count++;
if (count == urls.length) {
var zipFile = zip.generate({type: "blob"});
saveAs(zipFile, zipFilename);
}
});
});
Here is my xml
<a href="#" onclick="urls();">Download</a>
To insert Javascript into website xml you need to create a record template that inherits the website assets as follows -
<template id="custom_assets" inherit_id="website.assets_frontend" name="Custom Assets">
<xpath expr="." position="inside">
<script type="text/javascript" src="/...path to your custom js file"></script>
</xpath>
</template>