Last active
October 25, 2018 06:16
-
-
Save jopfre/304078ea0bf317bc96ef to your computer and use it in GitHub Desktop.
force download of files server and client side
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#server side force download of files ending with 'download.pdf' | |
<FilesMatch "download\.pdf$"> | |
ForceType application/octet-stream | |
Header set Content-Disposition attachment | |
</FilesMatch> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//client side, ie and ios opens in new tab | |
var IE = /*@cc_on!@*/false || !!document.documentMode; | |
var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream; | |
//on useraction e.g. click/submit | |
if(IE || iOS) { | |
window.open('https://info.ensono.com/rs/999-OHA-317/images/NA-AssessReport-20180810.pdf', '_blank'); | |
} | |
//anytime | |
var a = document.createElement('a'); | |
a.href = "download.pdf"; //same origin | |
a.setAttribute("download", ""); | |
a.setAttribute('target', '_blank'); | |
document.body.appendChild(a); | |
a.click(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
location ~* download\.pdf$ { | |
types { application/octet-stream .pdf; } | |
default_type application/octet-stream; | |
add_header Content-Disposition attachment; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment