Auto-closing a popup with a file to download

后端 未结 4 1715
误落风尘
误落风尘 2021-02-06 16:16

I have a file, named download.php, which contains a file to be downloaded, so it has the following headers (declared with PHP):

header(\"Content-Typ         


        
4条回答
  •  不知归路
    2021-02-06 16:35

    I have a somewhat different proposal, which worked fine in my case and does not have an arbitrary timeout:

    var newwindow = window.open("http://example.com/download.php");
    newwindow.focus();
    newwindow.onblur = function() {newwindow.close(); };
    

    When finishing the download the new window will eventually unfocus and close.

提交回复
热议问题