Skip to content

Instantly share code, notes, and snippets.

@ebinnion
Created February 25, 2013 04:58
Show Gist options
  • Save ebinnion/5027845 to your computer and use it in GitHub Desktop.
Save ebinnion/5027845 to your computer and use it in GitHub Desktop.
Download and Redirect in jQuery
$(".downloadLink").click(
function(e) {
e.preventDefault();
//open download link in new page
window.open( $(this).attr("href") );
//redirect current page to success page
window.location="www.example.com/success.html";
window.focus();
}
);
@ebinnion
Copy link
Author

ebinnion commented May 9, 2022

Hello @ragineeguptta - It's been 9 years since I wrote this Gist, so I don't recall what exactly I was trying to do here. My best guess after reading this is that I was wanting to:

  • Store a reference to the file to be downloaded in the href of the link
  • Open a new tab to download that file
  • Redirect the current window to a success page
  • Then refocus the current window, probably due to opening the file in a new tab

But, it's unclear to me.

Do you have something in a shareable state that I could look at?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment