doulv1760 2014-06-26 10:01
浏览 230
已采纳

window.close()在IE(11)/ Chrome中无法正常工作?

I'm making an AJAX call to a site which generates a query and then saves it to a .txt file.
This file should be downloaded after the AJAX was done and close that download window.
Howether IE closes it automatically and then tries to close the mainwindow, which shouldn't be closed.
Meanwhile Chrome only closes the download window which is what IE should do aswell..
Is there a workaround for this?

function start(){
   $.ajax({
        url: ('query.php'),
        type: 'POST',
        async:false,
        data: { 
        id: id,
        intnr: intnr
        },
        dataType: "html"
         })
          .done (function(response) { window.open('download.php');  window.close('download.php'); })
          .fail (function(xhr, textStatus, errorThrown) { alert(xhr.responseText); })
        ;
}

download.php is just :

<?php
header ( 'Content-Type: text/html');
header ( "Content-Disposition: 'attachment'; filename='File.txt'");
include ('/xx/xx/query.txt');
?>

EDIT : Workaround but it is working now..
shortened function to

.done (function(response) { var download_window = window.open('download.php'); })

added into download.php

<script>
var s = navigator.userAgent; 
if(s.indexOf("Chrome") > -1 == true) 
{ 
window.open('', '_self', ''); 
window.close();
}
</script>
  • 写回答

2条回答 默认 最新

  • dsx666666 2014-06-26 11:25
    关注

    How about this then:

    .done (function(response) {
        var download_window = window.open('download.php');
        download_window.close();
     })
    

    .. should make IE not close anything else.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题
  • ¥50 Oracle Kubernetes服务器集群主节点无法访问,工作节点可以访问
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
  • ¥15 gsoap生成onvif框架
  • ¥15 有关sql server business intellige安装,包括SSDT、SSMS。
  • ¥15 stm32的can接口不能收发数据
  • ¥15 目标检测算法移植到arm开发板
  • ¥15 利用JD51设计温度报警系统