Permalink
Browse files

update the example to work with IE 10/11

  • Loading branch information...
dduponchel committed Feb 15, 2014
1 parent a336db3 commit 62995090d9d752a774d020c0ee64771b38e5bcbf
Showing with 26 additions and 6 deletions.
  1. +26 −6 examples/download-zip-file.html
@@ -14,10 +14,12 @@ <h1><a href="../">JSZip</a> example : download the generated zip file</h1>
<p>Tip : check the source of the page !</p>
<h2>The data URL</h2>
<div>
+ Does not work in IE, has restrictions on the length.<br/>
<a href="#" id="data_uri">click to download</a>
</div>
-<h2>The Blob URL</h2>
+<h2>The Blob URL / saveAs</h2>
<div>
+ Works on firefox, chrome , opera &gt;= 15 and IE &gt;= 10.<br/>
<a href="#" id="blob">click to download</a>
</div>
<script type="text/javascript" src="../dist/jszip.js"></script>
@@ -27,14 +29,32 @@ <h2>The Blob URL</h2>
zip.file("Hello.txt", "Hello world\n");
// data URI
- document.getElementById('data_uri').href = "data:application/zip;base64," + zip.generate();
+ var dataUriLink = document.getElementById('data_uri');
+ dataUriLink.onclick = function () {
+ dataUriLink.href = "data:application/zip;base64," + zip.generate({type:"base64"});
+ dataUriLink.download = "hello.zip";
+ }
// Blob
var blobLink = document.getElementById('blob');
- try {
- blobLink.download = "hello.zip";
- blobLink.href = window.URL.createObjectURL(zip.generate({type:"blob"}));
- } catch(e) {
+ var saveAs = window.saveAs || (navigator.msSaveBlob && navigator.msSaveBlob.bind(navigator))
+ var blobDownloadSupported = JSZip.support.blob && (saveAs || window.URL && window.URL.createObjectURL);
+ if (blobDownloadSupported) {
+ blobLink.onclick = function () {
+ try {
+ var blob = zip.generate({type:"blob"});
+ if (saveAs) {
+ saveAs(blob, "hello.zip");
+ } else {
+ blobLink.download = "hello.zip";
+ blobLink.href = window.URL.createObjectURL(blob);
+ }
+ } catch(e) {
+ blobLink.innerHTML += " " + e;
+ }
+ return false;
+ };
+ } else {
blobLink.innerHTML += " (not supported on this browser)";
}
})();

0 comments on commit 6299509

Please sign in to comment.