You can open the file download in a separate window / tab, and check when it will be closed.
Example:
<script type='text/javascript'> function openTab(url, callback){ var popup = window.open(url, "_blank"); if(typeof callback == 'function'){ var interval = window.setInterval(function() { try { if (popup == null || popup.closed) { window.clearInterval(interval); callback(); } } catch (e) { } }, 500); } popup.focus(); } //JS document.getElementById('link-download').onclick = function (event){ openTab(event.target.href, function(){ /* Действия после старта скачивания */ window.location.reload(); }); return false; } //jQuery $(document).on('click', '.download-file', function(e){ e.preventDefault(); openTab(event.target.href, function(){ /* Действия после старта скачивания */ window.location.reload(); }); }); </script> <a href="/download.php?file='<?php echo $name;?>'" id="link-download" class="download-file">Скачать</a>
If there are problems in the download.php file, or the file is not found, and you want to close a new window / tab, you can simply output:
echo "<script type='text/javascript' charset='utf-8'>if(window.opener){window.close();}</script>";
PS Use one of the options either with the jQuery framework or on pure js , do not leave both.
PSS Example, for example, copy-paste may not work.
PSSS The tracking method for closing the window may not work.