As the title mentions, I am trying to download a file which is served with associated mime type via PHP script given by href URL, then reload the same page, but can't quite figure it out, here's what I have so far:
<a id="viewAttachmentLink" href="/path/to/script.php?id=123">View Attachment</a>
<script type='text/javascript'>
jquery('#viewAttachmentLink').bind('click', function() {
if (myFunction()) {
window.location.href = "jquery(this).attr('href')";
setTimeout(location.reload(), 400);
} else {
return false;
}
});
</script>
With this code, it will reload the page, but appears to not make the call to the PHP script.
As mentioned in the comments, I was able to get around the issue by adding a target="_new"
attribute to the link. So when the link was clicked it would send the request to the remote php script to another window, which would control the headers and start downloading the file, and the original window would reload as needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With