Skip to content

Instantly share code, notes, and snippets.

View ZakaCoding's full-sized avatar
🎃
Focusing

Zaka Noor ZakaCoding

🎃
Focusing
View GitHub Profile
@zynick
zynick / download-file.js
Created January 6, 2016 12:17
download file ('save as') using javascript xhr
// http://stackoverflow.com/a/23797348/1150427
xhr.open('POST', url, true);
xhr.responseType = 'arraybuffer';
xhr.onload = function () {
if (this.status === 200) {
var filename = "";
var disposition = xhr.getResponseHeader('Content-Disposition');
if (disposition && disposition.indexOf('attachment') !== -1) {
var filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;