Guest User

Untitled

a guest
Jun 22nd, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. <a href="../doc/quot.pdf" target=_blank>Click here to Download quotation</a>
  2.  
  3. Content-Disposition: attachment; filename=quot.pdf;
  4.  
  5. <a download="quot.pdf" href="../doc/quot.pdf">Click here to Download quotation</a>
  6.  
  7. (function (){
  8.  
  9. addEvent(window, "load", function (){
  10. if (isInternetExplorer())
  11. polyfillDataUriDownload();
  12. });
  13.  
  14. function polyfillDataUriDownload(){
  15. var links = document.querySelectorAll('a[download], area[download]');
  16. for (var index = 0, length = links.length; index<length; ++index) {
  17. (function (link){
  18. var dataUri = link.getAttribute("href");
  19. var fileName = link.getAttribute("download");
  20. if (dataUri.slice(0,5) != "data:")
  21. throw new Error("The XHR part is not implemented here.");
  22. addEvent(link, "click", function (event){
  23. cancelEvent(event);
  24. try {
  25. var dataBlob = dataUriToBlob(dataUri);
  26. forceBlobDownload(dataBlob, fileName);
  27. } catch (e) {
  28. alert(e)
  29. }
  30. });
  31. })(links[index]);
  32. }
  33. }
  34.  
  35. function forceBlobDownload(dataBlob, fileName){
  36. window.navigator.msSaveBlob(dataBlob, fileName);
  37. }
  38.  
  39. function dataUriToBlob(dataUri) {
  40. if (!(/base64/).test(dataUri))
  41. throw new Error("Supports only base64 encoding.");
  42. var parts = dataUri.split(/[:;,]/),
  43. type = parts[1],
  44. binData = atob(parts.pop()),
  45. mx = binData.length,
  46. uiArr = new Uint8Array(mx);
  47. for(var i = 0; i<mx; ++i)
  48. uiArr[i] = binData.charCodeAt(i);
  49. return new Blob([uiArr], {type: type});
  50. }
  51.  
  52. function addEvent(subject, type, listener){
  53. if (window.addEventListener)
  54. subject.addEventListener(type, listener, false);
  55. else if (window.attachEvent)
  56. subject.attachEvent("on" + type, listener);
  57. }
  58.  
  59. function cancelEvent(event){
  60. if (event.preventDefault)
  61. event.preventDefault();
  62. else
  63. event.returnValue = false;
  64. }
  65.  
  66. function isInternetExplorer(){
  67. return /*@cc_on!@*/false || !!document.documentMode;
  68. }
  69.  
  70. })();
Add Comment
Please, Sign In to add comment