Advertisement
Guest User

Untitled

a guest
May 25th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.32 KB | None | 0 0
  1. $("body").append("<iframe src='Document.ashx?clientid=123&documentid=10'></iframe>
  2. <iframe src='Document.ashx?clientid=123&documentid=11'></iframe>")
  3.  
  4. public void ProcessRequest (HttpContext context) {
  5.  
  6. ...
  7.  
  8. if (!string.IsNullOrEmpty(context.Request.QueryString["downloadid"]))
  9. Response.Cookies[context.Request.QueryString["downloadid"]].Value = "complete";
  10. }
  11.  
  12. function downloadFile(url, downloadid) {
  13. //set a cookie with a unique download id
  14. $.cookie(downloadid, 'pending', { path: '/' });
  15.  
  16. //create a new url
  17. var newurl = $.param.querystring(url, { downloadid: downloadid });
  18.  
  19. //append an iframe with new url
  20. $("body").append("<iframe style='height:0;width:0;' data-downloadid='" + downloadid + "' src='" + newurl + "'></iframe>");
  21. }
  22.  
  23. function downloadComplete(downloadid) {
  24. //check if download is pending
  25. return $.cookie(downloadid) == "complete";
  26. }
  27.  
  28. function downloadManager(arrDownloads) {
  29. //loop through download items backwards
  30. var allComplete = false;
  31. for (var i = arrDownloads.length; i > 0; i--) {
  32. if (downloadComplete(arrDownloads[i - 1].downloadid)) {
  33. //download the next one if it exists
  34. if (i == arrDownloads.length) {
  35. allComplete = true;
  36. }
  37. else {
  38. downloadFile(arrDownloads[i].url, arrDownloads[i].downloadid);
  39. }
  40. //stop checking for completed downloads
  41. break;
  42. }
  43. }
  44.  
  45. if (allComplete) {
  46. //remove cookies
  47. for (var i = arrDownloads.length; i > 0; i--) {
  48. $.cookie(arrDownloads[i - 1].downloadid, null, { path: '/' });
  49. }
  50.  
  51. //remove iframes
  52. $("iframe[data-downloadid]").remove();
  53. }
  54. else {
  55. setTimeout("downloadManager(" + JSON.stringify(arrDownloads) + ");", 500);
  56. }
  57. }
  58.  
  59. function downloadFiles(arrurls) {
  60. var arrDownloads = [];
  61.  
  62. for (var i = 0; i < arrurls.length; i++) {
  63. var item = new Object();
  64. item.url = arrurls[i];
  65. item.downloadid = newGuid();
  66. arrDownloads.push(item);
  67. }
  68.  
  69. //start the first download
  70. downloadFile(arrDownloads[0].url, arrDownloads[0].downloadid);
  71. //initiate the manager
  72. downloadManager(arrDownloads);
  73. }
  74.  
  75. $(function () {
  76. var arrurls = [];
  77. arrurls.push("Document.ashx?clientid=123&documentid=10");
  78. arrurls.push("Document.ashx?clientid=123&documentid=11");
  79. arrurls.push("Document.ashx?clientid=123&documentid=12");
  80. arrurls.push("Document.ashx?clientid=123&documentid=13");
  81. arrurls.push("Document.ashx?clientid=123&documentid=14");
  82. downloadFiles(arrurls);
  83. });
  84.  
  85. $("body").append("<iframe src='Document.ashx?clientid=123&documentid=10'>If you can read this, please use a newer browser</iframe>
  86. <iframe src='Document.ashx?clientid=123&documentid=11'>If you can read this, please use a newer browser</iframe>")
  87.  
  88. $("body").append("<iframe src='Document.ashx?clientid=123&documentid=10'>If you can read this, please use a newer browser</iframe>");
  89. $("body").append("<iframe src='Document.ashx?clientid=123&documentid=10'>If you can read this, please use a newer browser</iframe>");
  90.  
  91. Protected Sub DownloadFile(fileId As String)
  92. If Request.Browser.Browser = "Chrome" Then
  93. 'open iframes dynamically for multiple downloads
  94. ClientScript.RegisterStartupScript(Me.GetType(), fileId, _
  95. "<script language='javascript'>createIframeForDownloadHandler('" & fileId & "');</script>")
  96. Else
  97. 'open windows for multiple downloads
  98. ClientScript.RegisterStartupScript(Me.GetType(), fileId, _
  99. "<script language='javascript'>openWindowForDownloadHandler('" & fileId & "');</script>")
  100. End If
  101. End Sub
  102.  
  103. function openWindowForDownloadHandler(fileId) {
  104. //open a new window. setting height and width foces new window as opposed to new tab
  105. window.open('FileShareDownloadHandler.ashx?id=' + fileId, '_blank', 'width=100,height=100,left=0,top=0');
  106. }
  107.  
  108. function createIframeForDownloadHandler(fileId) {
  109. var element = document.createElement("iframe");
  110. element.setAttribute('id', 'myframe' + fileId);
  111. element.setAttribute('style', 'display:none;');
  112. element.setAttribute('src', 'FileShareDownloadHandler.ashx?id=' + fileId);
  113. document.body.appendChild(element);
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement