Skip to content

Instantly share code, notes, and snippets.

@simongong
Last active May 10, 2016 06:34
Show Gist options
  • Save simongong/5c2dca1e3935751443e61688209bc9f2 to your computer and use it in GitHub Desktop.
Save simongong/5c2dca1e3935751443e61688209bc9f2 to your computer and use it in GitHub Desktop.
JavsScript: get disposition header for response
function(userAgent, fileName) {
var suffix = '.zip';
if(userAgent.indexOf('msie') >= 0 || userAgent.indexOf('chrome') >= 0) {
return 'attachment; filename=' + encodeURIComponent(fileName) + suffix;
} else if(userAgent.indexOf('firefox') >= 0) {
return 'attachment; filename*="utf8\'\'' + encodeURIComponent(fileName)+'"' + suffix;
} else {
return 'attachment; filename=' + new Buffer(fileName).toString('binary') + suffix;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment