Reputation: 21
here my html
<a class="downloadLink" href="http://domainname.com/sample.pdf"></a>
here is my jquery
jQuery(".downloadLink").click(
function(e) {
e.preventDefault();
//open download link in new page
window.open( jQuery(this).attr("href") );
//redirect current page to success page
window.location="http://domainname.com/new-location";
window.focus();
}
);
This code is works file but need it to download the pdf the in same window then redirect to the new location with the same window.
Thanks in advance.
Upvotes: 0
Views: 2021
Reputation: 82
Though it is late, I think this might help for those who bump into this later.
jQuery('.downloadLink').on('click', function(e){
e.preventDefault();
//open download link in new page
var win = window.open( jQuery(this).attr("href") );
//redirect current page to success page
window.location="http://domainname.com/new-location";
win.close();
});
Upvotes: 0
Reputation: 999
Checkout jQueryFiledownload plugin (see the links to the documentation below), it will explain and resolve the issue you are having.
jQuery File Download is a cross server platform compatible jQuery plugin that allows for an Ajax-like file download experience that isn't normally possible using the web.
Hope this helps, Kevin
Upvotes: 1