Skip to content

Commit

Permalink
Fix export block as JSON in IE11 and Firefox (#10000)
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad authored and tofumatt committed Sep 19, 2018
1 parent 333a4c2 commit 120b20a
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions packages/list-reusable-blocks/src/utils/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,22 @@
* @param {string} contentType File mime type.
*/
export function download( fileName, content, contentType ) {
const a = document.createElement( 'a' );
const file = new window.Blob( [ content ], { type: contentType } );
a.href = URL.createObjectURL( file );
a.download = fileName;
a.click();

// IE11 can't use the click to download technique
// we use a specific IE11 technique instead.
if ( window.navigator.msSaveOrOpenBlob ) {
window.navigator.msSaveOrOpenBlob( file, fileName );
} else {
const a = document.createElement( 'a' );
a.href = URL.createObjectURL( file );
a.download = fileName;

a.style.display = 'none';
document.body.appendChild( a );
a.click();
document.body.removeChild( a );
}
}

/**
Expand Down

0 comments on commit 120b20a

Please sign in to comment.