Need a JavaScript Simple Code For Zip A Folder

393 views Asked by At

my web server is a simple html server. there is no node.js,no php so i wanna make a zip file by js of the directory "/public_html/alpha" mainly i wanna zip the alpha folder

I tried the jszip.js and zip.js but didnt work.why i dont know..

Here is the code:

<html>
<head>
<script src="/jszip.js"></script>

</head>

<body>

<p>Works on firefox, chrome , opera &gt;= 15 and IE &gt;= 10 (but NOT in compatibility view).</p>
<button id="blob" class="btn btn-primary">click to download</button>

<script>


var zip = new JSZip();
zip.file("readme.txt", "alpha");


jQuery("#blob").on("click", function () {
zip.generateAsync({type:"blob"}).then(function (blob) { // 1) generate the zip file
    saveAs(blob, "hello.zip");                          // 2) trigger the download
}, function (err) {
    jQuery("#blob").text(err);
});
});


</script>

</body>

</html>

This Code dont even give any result.

Server link : For Check Click Here

1

There are 1 answers

6
ryuzeke On

Add jquery on header

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

then in script make it like this

$(document).ready(function(){
  $("#blob").click(function(){
    // bla bla bla your code
  });
});