Skip to content

Instantly share code, notes, and snippets.

@adamrobbie
Created June 22, 2012 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamrobbie/2974111 to your computer and use it in GitHub Desktop.
Save adamrobbie/2974111 to your computer and use it in GitHub Desktop.
set a cookie on the response of the download request and have JavaScript to poll for that cookie. Once the download is ready to be served, the cookie will be available in JavaScript. To ensure working across various browser windows/tabs in the same sessio
function download() {
var token = new Date().getTime();
var wait = document.getElementById("wait");
wait.style.display = "block";
var pollDownload = setInterval(function() {
if (document.cookie.indexOf("download=" + token) > -1) {
document.cookie = "download=" + token + "; expires=" + new Date(0).toGMTString() + "; path=/";
wait.style.display = "none";
clearInterval(pollDownload);
}
}, 500);
window.location = "download?token=" + token;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment