Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/471.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 浏览器mimetype预览支持_Javascript - Fatal编程技术网

Javascript 浏览器mimetype预览支持

Javascript 浏览器mimetype预览支持,javascript,Javascript,我当前正在从服务器检索一个文件,我在响应头中设置了Content-Disposition:inline。这将在浏览器中预览支持的文件,或在不支持预览的情况下下载文件。文件将在一个新选项卡中打开,您可以从下面的代码中看到该选项卡 下载文档(id:string){ const documentWindow=window.open('',''u blank'); 如果(文档窗口){ documentWindow.opener=null; } 让endpoint=Endpoints.getId(End

我当前正在从服务器检索一个文件,我在响应头中设置了
Content-Disposition:inline
。这将在浏览器中预览支持的文件,或在不支持预览的情况下下载文件。文件将在一个新选项卡中打开,您可以从下面的代码中看到该选项卡

下载文档(id:string){
const documentWindow=window.open('',''u blank');
如果(文档窗口){
documentWindow.opener=null;
}
让endpoint=Endpoints.getId(Endpoints.Document,id);
this.genericService.getAll(端点)。订阅(
响应=>{
const claim=response.claim;
端点=`${endpoint}/c?=${claim}`;
如果(文档窗口){
documentWindow.location.href=端点;
}
}
);

}
这就是我的结局。我会等到文件的url准备好后再打开文件。这扇窗户第一次会被堵住,因为我们要等一次往返才能打开一扇新的窗户。如果窗口被阻止,我会向用户显示一些消息,告诉他们停用该站点的弹出窗口阻止程序

下载文档(id:string){
让endpoint=Endpoints.getId(Endpoints.Document,id);
this.genericService.getAll(endpoint.subscribe)(
响应=>{
const claim=response.claim;
端点=`${endpoint}/c?=${claim}`;
const documentWindow=window.open(端点“_blank”);
如果(文档窗口){
documentWindow.opener=null;
}否则{
//向用户显示一些信息以关闭站点的弹出窗口阻止程序
}
}
);

}
“或者至少我希望能够在下载开始后关闭新选项卡”-哪个浏览器不会自动关闭?Chrome当然有。Longshot:您的代码是从上述服务器获取的吗?(即相同来源是否清晰?)然后您可以尝试在已打开的窗口中读取文档,查看文档是否已关闭或为空(可能已下载)或包含某些内容(可能受支持)。@Quentin使用上述代码,它不会在Chrome中自动关闭。@andbjer
window.open(url)
。这不是因为你正在设置它的
位置。href
在它被打开后。@kaido谢谢!我这样做的原因是为了防止窗户被堵住。有没有办法同时做到这两件事?