dq_609586475 2014-12-21 22:31
浏览 91
已采纳

JavaScript从target = _blank提交表单中检索窗口句柄

I'm trying to create an automated script that lets me download various files from a website, then upload them to a new website. The script will let multiple users copy content from the old site to the new one at the same time.

I initially attempted to use AJAX to download one file at a time, and store the file(s) data in variables, then upload this variable (file data) to the second domain. The download worked fine, but the PHP page on the second domain always threw back a 500 request error message AFTER uploading, despite setting various file size parameters and processing time parameters in PHP. This meant I couldnt even see what was echoed by the PHP page to debug, and continue developing that method.

After spending a long time trying to fix this (and failing miserably), I decided to just let the users download the old files normally, then use a form to upload the files. As I want the script to continue to run whilst the file is uploading, I've decided to set the forms target to "_blank" to open a new tab (which uploads the file).

How can I retrieve the windows handle that's opened with the target="_blank" form, to test when the window is closed? I don't need to access the windows HTML, I just want to check when it closes. The page that's opened by the form is not on the same domain as the form that opens it, but the "Access-Control-Allow-Origin" header is set to "*" on the second domains PHP page.

  • 写回答

1条回答 默认 最新

  • doutuohan6606 2014-12-22 05:14
    关注

    I don't think you can retrieve the window handle, but you can use Javascript to keep a reference to the window and check whether the window is closed or not. You would have to open your window with Javascript like this

    var uploadWindow = window.open("http://www.google.com");
    

    Then you can use a function on a timer to monitor if the window has closed or not:

    var interval = 250;
    setTimeout(checkClose, interval);
    
    function checkClose() {
        if (uploadWindow.closed) {
            // Code to run when window is closed
        }
        else {
            setTimeout(checkClose, interval);
        }
    }
    

    I hope this can be of help

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 在使用abaqus软件中,继承到assembly里的surfaces怎么使用python批量调动
  • ¥15 大一C语言期末考试,求帮助🙏🙏
  • ¥15 ch340驱动未分配COM
  • ¥15 Converting circular structure to JSON
  • ¥30 Hyper-v虚拟机相关问题,求解答。
  • ¥15 TSM320F2808PZA芯片 Bootloader
  • ¥45 谷歌浏览器出现开发者工具无法显示已创建的,但您可以调试已部署的代码。 状态代码 404, net::ERR HTTP RESPONSE CODE FAILURE
  • ¥15 如何解决蓝牙通话音频突发失真问题
  • ¥15 安装opengauss数据库报错
  • ¥15 【急】在线问答CNC雕刻机的电子电路与编程