2 title: "Download the generated zip file"
7 <p>Tip : check the source of the page !</p>
8 <h2>The FileSaver API</h2>
10 Works on firefox, chrome , opera >= 15 and IE >= 10 (but NOT in compatibility view).<br/>
11 <button id="blob" class="btn btn-primary">click to download</button>
15 Does not work in IE, has restrictions on the length.<br/>
16 <button id="data_uri" class="btn btn-primary">click to download</button>
18 <script type="text/javascript">
20 var zip = new JSZip();
21 zip.file("Hello.txt", "Hello world\n");
23 function bindEvent(el, eventName, eventHandler) {
24 if (el.addEventListener){
26 el.addEventListener(eventName, eventHandler, false);
27 } else if (el.attachEvent){
29 el.attachEvent('on'+eventName, eventHandler);
34 var blobLink = document.getElementById('blob');
35 if (JSZip.support.blob) {
36 function downloadWithBlob() {
38 var blob = zip.generate({type:"blob"});
40 saveAs(blob, "hello.zip");
42 blobLink.innerHTML += " " + e;
46 bindEvent(blobLink, 'click', downloadWithBlob);
48 blobLink.innerHTML += " (not supported on this browser)";
52 function downloadWithDataURI() {
53 window.location = "data:application/zip;base64," + zip.generate({type:"base64"});
55 var dataUriLink = document.getElementById('data_uri');
56 bindEvent(dataUriLink, 'click', downloadWithDataURI);