2013-04-27 11 views
5

Tôi có một số tệp và sau khi tìm nạp chúng, tôi chuyển đổi chúng thành zip bằng cách sử dụng JSZip, nhưng điều này không hoạt động trong Internet Explorer và Safari dưới dạng JSZip không hoạt động trong IE với URL cho một số nội dung.Tạo tệp Zip bằng Javascript (JSZip) không hoạt động trong IE và Safari

var zip = new JSZip(); 
var linkArr=$(xml1).find('groupnode:eq('+id_no+')').find('link'); 
var linklength = $(linkArr).length; 

for(i=0;i<linklength;i++) 
{ 
    zip.file("../resources"+$(linkArr[i]).attr('src'),$(linkArr[i]).text()); 
} 

content = zip.generate(); 
location.href="data:application/zip;base64," + content; 

Bạn có biết bất kỳ giải pháp nào khác cung cấp hỗ trợ trình duyệt chéo không?

+0

Trang web JSZip thấy rằng tất cả các trình duyệt làm việc, nhưng chỉ IE không làm việc với các URL và một số nội dung, nhưng nó không làm việc với Safari. Rất có thể, bạn có thể thay đổi cách bạn đang thực hiện nó để làm cho nó hoạt động. – pickypg

+2

có vẻ hoạt động tốt trong bản trình diễn này ':)' safari http://htanjo.github.io/jszip-demo/ –

+0

bản trình diễn ở trên gặp sự cố Safari. Tôi nghĩ rằng thông tin trong câu trả lời/bình luận ở đây là lỗi thời, như người tạo ra JSZip đã tuyên bố rằng hỗ trợ tải xuống các đốm màu không tồn tại cho Safari hoặc IE. – volx757

Trả lời

3

http://stuk.github.io/jszip/

Great deal hỗ trợ trình duyệt chéo, bao gồm IE và Safari, vấn đề nằm trong mã của bạn hoặc URL của. Tôi sẽ điều chỉnh URL của bạn và điều tra mã khác có thể gây ra sự cố trước khi chuyển sang giải pháp khác.

Cũng đọc phần về các vấn đề filename trong URL tôi cung cấp:

"Filename problems 
The biggest issue with JSZip is that the filenames are very awkward, Firefox generates filenames such as a5sZQRsx.zip.part (see bugs 367231 and 532230), and Safari isn't much better with just Unknown. Sadly there is no pure Javascript solution (and working in every browsers) to this. However... 

Solution-ish: Downloadify 

Downloadify uses a small Flash SWF to download files to a user's computer with a filename that you can choose. Doug Neiner has added the dataType option to allow you to pass a zip for downloading. Follow the Downloadify demo with the following changes: 

zip = new JSZip(); 
zip.add("Hello.", "hello.txt"); 
Downloadify.create('downloadify',{ 
... 
    data: function(){ 
    return zip.generate(); 
    }, 
... 
    dataType: 'base64' 
}); 
Other solution-ish: Blob URL 

With some recent browsers come a new way to download Blobs (a zip file for example) : blob urls. The download attribute on <a> allows you to give the name of the file. Blob urls start to be widely supported but this attribute is currently only supported in Chrome and Firefox (>= 20). See the example. 

var blob = zip.generate({type:"blob"}); 
myLink.href = window.URL.createObjectURL(blob); 
myLink.download = "myFile.zip";"