Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: kennethjiang/js-file-download
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 431da63a97d6bdc79db2bdef28fa25c457a93510
Choose a base ref
...
head repository: kennethjiang/js-file-download
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ece02414ad48337825a32405868c37237530d73b
Choose a head ref

Commits on May 22, 2019

  1. BOM support

    lukaszflorczak authored May 22, 2019
    3
    Copy the full SHA
    8a2b1cf View commit details
  2. Merge pull request #48 from lukaszflorczak/master

    Thank you @lukaszflorczak for your contribution.
    kennethjiang authored May 22, 2019
    Copy the full SHA
    a186749 View commit details
  3. bump version to 0.4.6

    kennethjiang committed May 22, 2019
    Copy the full SHA
    055630b View commit details

Commits on May 23, 2019

  1. IE 11 Fixes

    akshaybandivadekar committed May 23, 2019
    Copy the full SHA
    793559f View commit details

Commits on May 24, 2019

  1. Copy the full SHA
    13e26af View commit details
  2. bump version to 0.4.7

    kennethjiang committed May 24, 2019
    Copy the full SHA
    2b6e325 View commit details

Commits on Aug 19, 2019

  1. Fix missing bom arg in d.ts

    ypresto authored Aug 19, 2019
    Copy the full SHA
    f513d35 View commit details

Commits on Aug 20, 2019

  1. Merge pull request #52 from ypresto/patch-1

    Fix missing bom arg in d.ts
    kennethjiang authored Aug 20, 2019
    Copy the full SHA
    3a49439 View commit details
  2. bump version 0.4.8

    kennethjiang committed Aug 20, 2019
    Copy the full SHA
    cab17e3 View commit details

Commits on Dec 9, 2019

  1. Fixes iOS Safari error.

    exihuatl authored Dec 9, 2019
    Copy the full SHA
    d71d676 View commit details

Commits on Dec 11, 2019

  1. Merge pull request #55 from exihuatl/patch-1

    Fixes iOS Safari error.
    
    Thanks @exihuatl
    kennethjiang authored Dec 11, 2019
    Copy the full SHA
    dba8d22 View commit details
  2. bump version 0.4.9

    kennethjiang committed Dec 11, 2019
    Copy the full SHA
    77f0db7 View commit details

Commits on Feb 18, 2020

  1. Copy the full SHA
    c2304eb View commit details
  2. Merge pull request #57 from guoqchen1001/master

    fix bug window.URL.createObjectURL is not a function
    kennethjiang authored Feb 18, 2020
    Copy the full SHA
    129a881 View commit details
  3. bump version 0.4.10

    kennethjiang committed Feb 18, 2020
    Copy the full SHA
    6809f82 View commit details

Commits on Mar 3, 2020

  1. Copy the full SHA
    a1bf43b View commit details
  2. Copy the full SHA
    82163de View commit details

Commits on Mar 31, 2020

  1. Copy the full SHA
    9052526 View commit details
  2. Copy the full SHA
    4a90b76 View commit details
  3. Copy the full SHA
    1bb5ecf View commit details
  4. bump version 0.4.11

    kennethjiang committed Mar 31, 2020
    Copy the full SHA
    1e7eb4d View commit details

Commits on May 6, 2020

  1. Copy the full SHA
    9a721b5 View commit details
  2. Merge pull request #63 from robmarshall/master

    Update file-download.js
    kennethjiang authored May 6, 2020
    Copy the full SHA
    543c29d View commit details
  3. bump version 0.4.12

    kennethjiang committed May 6, 2020
    Copy the full SHA
    ece0241 View commit details
Showing with 20 additions and 14 deletions.
  1. +17 −12 file-download.js
  2. +2 −1 js-file-download.d.ts
  3. +1 −1 package.json
29 changes: 17 additions & 12 deletions file-download.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
module.exports = function(data, filename, mime) {
var blob = new Blob([data], {type: mime || 'application/octet-stream'});
module.exports = function(data, filename, mime, bom) {
var blobData = (typeof bom !== 'undefined') ? [bom, data] : [data]
var blob = new Blob(blobData, {type: mime || 'application/octet-stream'});
if (typeof window.navigator.msSaveBlob !== 'undefined') {
// IE workaround for "HTML7007: One or more blob URLs were
// revoked by closing the blob for which they were created.
// These URLs will no longer resolve as the data backing
// IE workaround for "HTML7007: One or more blob URLs were
// revoked by closing the blob for which they were created.
// These URLs will no longer resolve as the data backing
// the URL has been freed."
window.navigator.msSaveBlob(blob, filename);
}
else {
var blobURL = window.URL.createObjectURL(blob);
var blobURL = (window.URL && window.URL.createObjectURL) ? window.URL.createObjectURL(blob) : window.webkitURL.createObjectURL(blob);
var tempLink = document.createElement('a');
tempLink.style.display = 'none';
tempLink.href = blobURL;
tempLink.setAttribute('download', filename);
tempLink.setAttribute('download', filename);

// Safari thinks _blank anchor are pop ups. We only want to set _blank
// target if the browser does not support the HTML5 download attribute.
// This allows you to download files in desktop safari if pop up blocking
// This allows you to download files in desktop safari if pop up blocking
// is enabled.
if (typeof tempLink.download === 'undefined') {
tempLink.setAttribute('target', '_blank');
}

document.body.appendChild(tempLink);
tempLink.click();
document.body.removeChild(tempLink);
window.URL.revokeObjectURL(blobURL);

// Fixes "webkit blob resource error 1"
setTimeout(function() {
document.body.removeChild(tempLink);
window.URL.revokeObjectURL(blobURL);
}, 200)
}
}
3 changes: 2 additions & 1 deletion js-file-download.d.ts
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ declare module 'js-file-download' {
export default function fileDownload(
data: string | ArrayBuffer | ArrayBufferView | Blob,
filename: string,
mime?: string
mime?: string,
bom?: string
): void;
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "js-file-download",
"version": "0.4.5",
"version": "0.4.12",
"description": "Javascript function that triggers browser to save javascript-generated content to a file",
"main": "file-download.js",
"scripts": {