Comparing version 1.4.1 to 1.4.2
@@ -109,4 +109,5 @@ | ||
if(typeof safari !=="undefined" ){ // handle non-a[download] safari as best we can: | ||
url="data:"+url.replace(/^data:([\w\/\-\+]+)/, u); | ||
// handle non-a[download] safari as best we can: | ||
if(/(Version)\/(\d+)\.(\d+)(?:\.(\d+))?.*Safari\//.test(navigator.userAgent)) { | ||
url=url.replace(/^data:([\w\/\-\+]+)/, u); | ||
if(!window.open(url)){ // popup blocked, offer direct download: | ||
@@ -113,0 +114,0 @@ if(confirm("Displaying New Document\n\nUse Save As... to download, then click back to return to this page.")){ location.href=url; } |
{ | ||
"name": "downloadjs", | ||
"main": "download.js", | ||
"version": "1.4.1", | ||
"version": "1.4.2", | ||
"description": "file downloading using client-side javascript", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
@@ -6,4 +6,6 @@ download | ||
--------- | ||
The download() function is used to trigger a file download from JavaScript. It specifies the contents and name of a new file placed in the browser's download directory. The input can be a String, Blob, or Typed Array of data, or via a dataURL representing the file's data as base64 or url-encoded string. No matter the input format, download() saves a file using the specified file name and mime information in the same manner as a server using a Content-Disposition HTTP header. | ||
The download() function is used to trigger a file download from JavaScript. | ||
It specifies the contents and name of a new file placed in the browser's download directory. The input can be a URL, String, Blob, or Typed Array of data, or via a dataURL representing the file's data as base64 or url-encoded string. No matter the input format, download() saves a file using the specified file name and mime information in the same manner as a server using a Content-Disposition HTTP header. | ||
Syntax | ||
@@ -43,3 +45,2 @@ --------- | ||
#### text dataURL - [live demo](http://pagedemos.com/sxks39b72aqb/2) | ||
@@ -51,2 +52,6 @@ download("data:text/plain,hello%20world", "dlDataUrlText.txt", "text/plain"); | ||
#### text url - [live demo](http://pagedemos.com/pz6hkyqutjtw/) | ||
download("/robots.txt"); | ||
#### text UInt8 Array - [live demo](http://pagedemos.com/sxks39b72aqb/4) | ||
@@ -68,2 +73,4 @@ var str= "hello world", arr= new Uint8Array(str.length); | ||
#### ajax callback - [live demo](http://pagedemos.com/sxks39b72aqb/7) | ||
(note that callback mode won't work on vanilla ajax or with binary files) | ||
$.ajax({ | ||
@@ -75,3 +82,14 @@ url: "/download.html", | ||
### Binary Files | ||
#### image from URL - [live demo](http://pagedemos.com/yvvmxbjrwq7u/) | ||
download("/diff6.png"); | ||
#### Image via ajax for custom filename - [live demo](http://pagedemos.com/v2848zfgwrju/) | ||
var x=new XMLHttpRequest(); | ||
x.open( "GET", "/diff6.png" , true); | ||
x.responseType="blob"; | ||
x.onload= function(e){download(e.target.response, "awesomesauce.png", "image/png");}; | ||
x.send(); | ||
Compatibility | ||
@@ -91,4 +109,14 @@ --------- | ||
Change Log (v4) | ||
FAQ | ||
--------- | ||
* `Can I tell when a download is done/canceled?` No. | ||
* `How can I style the temporary download link?` Define CSS class styles for `.download-js-link`. | ||
* `What's up with Safari?` I don't know either but pull requests that improve the situation are welcome. | ||
* `Why is my binary file corrupted?` Likely: an incorrect MIME or using jQuery ajax, which has no bin support. | ||
* `How big of files work?` Depends, try yourself: [File Echo Demo](http://pagedemos.com/gqs6hbmjcpem/)... I do a 1GB dl routinely on a thinkpad... | ||
Change Log (v4.1) | ||
--------- | ||
* 2008 :: landed a FF+Chrome compat way of downloading strings to local un-named files, upgraded to use a hidden frame and optional mime | ||
@@ -98,2 +126,3 @@ * 2012 :: added named files via a[download], msSaveBlob() for IE (10+) support, and window.URL support for larger+faster saves than dataURLs | ||
* 2015 :: converted to amd/commonJS module with browser-friendly fallback | ||
* 2015 :: 4.1 added direct URL downloading via a single URL argument. | ||
* 20XX :: ???? Considering Zip, Tar, and other multi-file outputs, Blob.prototype.download option, and more, stay tuned folks. |
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
24462
5
139
122
1