Auto-closing a popup with a file to download

后端 未结 4 1705
误落风尘
误落风尘 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:20

    Can I ask what it says in the browser url bar in this opened window. It might be the case that the browser see's the headers letting the browser know it is to be treated as a download and doesn't run the window as a true page. and instead opens something like 'about:blank'. If that's the case the on the page javascript would never get run.

    I can suggest the following however. I'm assuming this window is being opened by another page. In that case have the other page open the window programatically through javascript and control the close from there.

    var popout = window.open("http://example.com/download.php");
    window.setTimeout(function(){
        popout.close();
    }, 1000);
    

提交回复
热议问题