Skip to content

Instantly share code, notes, and snippets.

@sms-system
Last active August 29, 2015 14:04
Show Gist options
  • Save sms-system/4b3abe7cfa3d9970d847 to your computer and use it in GitHub Desktop.
Save sms-system/4b3abe7cfa3d9970d847 to your computer and use it in GitHub Desktop.
Скачать програмно файл по ссылке (http://pixelscommander.com/javascript/javascript-file-download-ignore-content-type/)
window.downloadFile = function(url,name) {
if (window.downloadFile.isChrome || window.downloadFile.isSafari) {
var link = document.createElement('a');
link.href = url;
if (link.download !== undefined){
var fileName = url.substring(url.lastIndexOf('/') + 1, url.length);
link.download = name?name:fileName;
}
if (document.createEvent) {
var e = document.createEvent('MouseEvents');
e.initEvent('click' ,true ,true);
link.dispatchEvent(e);
return true;
}
}
var query = '?download';
window.open(sUrl + query, '_self');
}
window.downloadFile.isChrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
window.downloadFile.isSafari = navigator.userAgent.toLowerCase().indexOf('safari') > -1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment