Php window.close()在IE(11)/Chrome中工作不正常?
我正在对一个站点进行AJAX调用,该站点生成一个查询,然后将其保存到一个.txt文件中。Php window.close()在IE(11)/Chrome中工作不正常?,php,ajax,internet-explorer,google-chrome,download,Php,Ajax,Internet Explorer,Google Chrome,Download,我正在对一个站点进行AJAX调用,该站点生成一个查询,然后将其保存到一个.txt文件中。 此文件应在AJAX完成后下载,并关闭下载窗口。 但是IE会自动关闭它,然后尝试关闭主窗口,而主窗口不应关闭。 同时,Chrome只关闭下载窗口,IE也应该这样做。 有解决办法吗 function start(){ $.ajax({ url: ('query.php'), type: 'POST', async:false, data: {
此文件应在AJAX完成后下载,并关闭下载窗口。
但是IE会自动关闭它,然后尝试关闭主窗口,而主窗口不应关闭。
同时,Chrome只关闭下载窗口,IE也应该这样做。
有解决办法吗
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); })
;
}
下载.php只是:
<?php
header ( 'Content-Type: text/html');
header ( "Content-Disposition: 'attachment'; filename='File.txt'");
include ('/xx/xx/query.txt');
?>
添加到download.php中
<script>
var s = navigator.userAgent;
if(s.indexOf("Chrome") > -1 == true)
{
window.open('', '_self', '');
window.close();
}
</script>
var s=navigator.userAgent;
如果(s.indexOf(“Chrome”)>-1==true)
{
窗口。打开(“”,“”,“”);
window.close();
}
这并不能真正回答您的问题,但提供了另一种选择
在jQuery代码中尝试以下操作:
.done (function(response) { window.location.href = "download.php"; })
。。并在download.php中添加标题以强制下载:
header("Content-Description: File Transfer");
header("Content-Type: application/download");
header("Content-Type: application/force-download");
// Removed this from my code.
// header("Content-Type: application/octet-stream");
// Added this for yours.. not sure exactly what's optimal for your case.
header("Content-Type: text/html");
header("Content-Transfer-Encoding: binary");
header("Content-Disposition: attachment; filename=File.txt");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Expires: 0");
header("Pragma: public");
ob_clean();
flush();
readfile("/xx/xx/query.txt");
在我的项目中,这段php代码是在单击提交按钮(表单)后运行的,如果我没记错的话,它只是显示了一个下载对话框,没有更新地址栏或显示一个空页面。这并没有真正回答您的问题,但提供了一个替代方案 在jQuery代码中尝试以下操作:
.done (function(response) { window.location.href = "download.php"; })
。。并在download.php中添加标题以强制下载:
header("Content-Description: File Transfer");
header("Content-Type: application/download");
header("Content-Type: application/force-download");
// Removed this from my code.
// header("Content-Type: application/octet-stream");
// Added this for yours.. not sure exactly what's optimal for your case.
header("Content-Type: text/html");
header("Content-Transfer-Encoding: binary");
header("Content-Disposition: attachment; filename=File.txt");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Expires: 0");
header("Pragma: public");
ob_clean();
flush();
readfile("/xx/xx/query.txt");
在我的项目中,这段php代码是在单击提交按钮(表单)后运行的,如果我没记错的话,它只是显示了一个下载对话框,没有更新地址栏或显示一个空页面。这并没有真正回答您的问题,但提供了一个替代方案 在jQuery代码中尝试以下操作:
.done (function(response) { window.location.href = "download.php"; })
。。并在download.php中添加标题以强制下载:
header("Content-Description: File Transfer");
header("Content-Type: application/download");
header("Content-Type: application/force-download");
// Removed this from my code.
// header("Content-Type: application/octet-stream");
// Added this for yours.. not sure exactly what's optimal for your case.
header("Content-Type: text/html");
header("Content-Transfer-Encoding: binary");
header("Content-Disposition: attachment; filename=File.txt");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Expires: 0");
header("Pragma: public");
ob_clean();
flush();
readfile("/xx/xx/query.txt");
在我的项目中,这段php代码是在单击提交按钮(表单)后运行的,如果我没记错的话,它只是显示了一个下载对话框,没有更新地址栏或显示一个空页面。这并没有真正回答您的问题,但提供了一个替代方案 在jQuery代码中尝试以下操作:
.done (function(response) { window.location.href = "download.php"; })
。。并在download.php中添加标题以强制下载:
header("Content-Description: File Transfer");
header("Content-Type: application/download");
header("Content-Type: application/force-download");
// Removed this from my code.
// header("Content-Type: application/octet-stream");
// Added this for yours.. not sure exactly what's optimal for your case.
header("Content-Type: text/html");
header("Content-Transfer-Encoding: binary");
header("Content-Disposition: attachment; filename=File.txt");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Expires: 0");
header("Pragma: public");
ob_clean();
flush();
readfile("/xx/xx/query.txt");
在我的项目中,这段php代码是在单击“提交”按钮(表单)后运行的,如果我没记错的话,它只是显示了一个下载对话框,没有更新地址栏或显示一个空页面。那么这样如何:
.done (function(response) {
var download_window = window.open('download.php');
download_window.close();
})
。。应该让IE不要关闭任何其他东西。那么这个怎么样:
.done (function(response) {
var download_window = window.open('download.php');
download_window.close();
})
。。应该让IE不要关闭任何其他东西。那么这个怎么样:
.done (function(response) {
var download_window = window.open('download.php');
download_window.close();
})
。。应该让IE不要关闭任何其他东西。那么这个怎么样:
.done (function(response) {
var download_window = window.open('download.php');
download_window.close();
})
。。应使IE不关闭任何其他内容。如果是rad窗口,则此功能将起作用
function GetRadWindow() {
var oWindow = null;
if (window.radWindow)
oWindow = window.radWindow;
else if (window.frameElement && window.frameElement.radWindow)
oWindow = window.frameElement.radWindow;
return oWindow;
}
function selfClose(){
GetRadWindow().close();
}
这将工作,如果它是rad窗口
function GetRadWindow() {
var oWindow = null;
if (window.radWindow)
oWindow = window.radWindow;
else if (window.frameElement && window.frameElement.radWindow)
oWindow = window.frameElement.radWindow;
return oWindow;
}
function selfClose(){
GetRadWindow().close();
}
这将工作,如果它是rad窗口
function GetRadWindow() {
var oWindow = null;
if (window.radWindow)
oWindow = window.radWindow;
else if (window.frameElement && window.frameElement.radWindow)
oWindow = window.frameElement.radWindow;
return oWindow;
}
function selfClose(){
GetRadWindow().close();
}
这将工作,如果它是rad窗口
function GetRadWindow() {
var oWindow = null;
if (window.radWindow)
oWindow = window.radWindow;
else if (window.frameElement && window.frameElement.radWindow)
oWindow = window.frameElement.radWindow;
return oWindow;
}
function selfClose(){
GetRadWindow().close();
}
如果创建一个HTML链接download.php,然后单击它,会发生什么?它是否显示query.txt或打开下载对话框?如果它显示文件,请修改download.php中的标题以强制下载query.txt,而不是使用window.open和.close,只需使用window.location=“download.php”(或类似的函数)加载即可。如果这样做,它将下载文件。但是,在query.txt被填充并下载之后,我如何实现这一点呢?我唯一的想法是打开download.php窗口。如果创建一个到download.php的HTML链接,然后单击它,会发生什么?它是否显示query.txt或打开下载对话框?如果它显示文件,请修改download.php中的标题以强制下载query.txt,而不是使用window.open和.close,只需使用window.location=“download.php”(或类似的函数)加载即可。如果这样做,它将下载文件。但是,在query.txt被填充并下载之后,我如何实现这一点呢?我唯一的想法是打开download.php窗口。如果创建一个到download.php的HTML链接,然后单击它,会发生什么?它是否显示query.txt或打开下载对话框?如果它显示文件,请修改download.php中的标题以强制下载query.txt,而不是使用window.open和.close,只需使用window.location=“download.php”(或类似的函数)加载即可。如果这样做,它将下载文件。但是,在query.txt被填充并下载之后,我如何实现这一点呢?我唯一的想法是打开download.php窗口。如果创建一个到download.php的HTML链接,然后单击它,会发生什么?它是否显示query.txt或打开下载对话框?如果它显示文件,请修改download.php中的标题以强制下载query.txt,而不是使用window.open和.close,只需使用window.location=“download.php”(或类似的函数)加载即可。如果这样做,它将下载文件。但是,在query.txt被填充并下载之后,我如何实现这一点呢?我唯一的想法是打开下载窗口。php..对我不起作用,可能是因为我有包含函数的页面吗?它只是跳转到我的第一个导航选项卡。你指的是哪一页和什么功能?我有一个包含4页导航栏的视图,全部包括在内。在4号有一个按钮,点击它运行函数start()。我已经关注了你的TIPP,但点击后它跳到了第一个导航选项卡:/n你有指向此页面的链接吗?如果键入download.php的完整地址并手动加载,会发生什么情况?你有下载窗口吗?它是通过和onclick函数完成的。是的,当我键入download.php地址时,我会看到下载窗口。这对我不起作用,可能是因为我有包含函数的页面吗?它只是跳转到我的第一个导航选项卡。你指的是哪一页和什么功能?我有一个包含4页导航栏的视图,全部包括在内。在4号有一个按钮,点击它运行函数start()。我已经关注了你的TIPP,但点击后它跳到了第一个导航选项卡:/n你有指向此页面的链接吗?如果键入download.php的完整地址并手动加载,会发生什么情况?你有下载窗口吗?它是通过和onclick函数完成的。是的,当我键入