有没有办法阻止 IE10/IE11 显示打开或保存提示
Is there a way to stop IE10/IE11 from showing open or save prompt
我正在使用 javascript 类似
的 blob 从服务器下载文件
let blob = new Blob([resposne['_body']], { type: contentType });
if (navigator.msSaveBlob) {
navigator.msSaveOrOpenBlob(blob, fileName); // in case of IE
} else {
let objectUrl = window.URL.createObjectURL(blob);
window.open(objectUrl);
}
上面的代码工作正常,但在 IE 中它显示一个对话框:
此外,如果我将直接 pdf link 放在 href 标签中,那么它也可以正常工作。所以看起来adobe插件没有问题。
我想要的是直接打开文件而不是显示这个提示。我尝试了 Registry hack as suggested here 但没有任何运气。知道如何实现这一目标吗?
对于面临相同问题的任何人,我使用 window.open
解决了它。我没有下载响应,而是直接将 URL 传递给 window.open
,例如
window.open(apiUrl) // Exmp "host:api/documents/download?id=1"
注意:-API 应该 returns 设置 header 类型的流响应。在我的例子中,C# web API 方法是
public HttpResponseMessage Download(int id)
{
var data = _service.Download(id);
HttpResponseMessage result = null;
result = Request.CreateResponse(HttpStatusCode.OK);
result.Content = new ByteArrayContent(data);//here data is byte[]
var name = data.Name.ToLower().Contains(data.DocType.ToLower())
? data.Name
: $"{data.Name}{data.DocType}";
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("inline")
{
FileName = name
};
result.Content.Headers.ContentType = new MediaTypeHeaderValue(MimeMapping.GetMimeMapping(name));
//here i am setting up the headers content type for example 'text/application-json'
return result;
}
希望对大家有所帮助。
我正在使用 javascript 类似
的 blob 从服务器下载文件let blob = new Blob([resposne['_body']], { type: contentType });
if (navigator.msSaveBlob) {
navigator.msSaveOrOpenBlob(blob, fileName); // in case of IE
} else {
let objectUrl = window.URL.createObjectURL(blob);
window.open(objectUrl);
}
上面的代码工作正常,但在 IE 中它显示一个对话框:
此外,如果我将直接 pdf link 放在 href 标签中,那么它也可以正常工作。所以看起来adobe插件没有问题。
我想要的是直接打开文件而不是显示这个提示。我尝试了 Registry hack as suggested here 但没有任何运气。知道如何实现这一目标吗?
对于面临相同问题的任何人,我使用 window.open
解决了它。我没有下载响应,而是直接将 URL 传递给 window.open
,例如
window.open(apiUrl) // Exmp "host:api/documents/download?id=1"
注意:-API 应该 returns 设置 header 类型的流响应。在我的例子中,C# web API 方法是
public HttpResponseMessage Download(int id)
{
var data = _service.Download(id);
HttpResponseMessage result = null;
result = Request.CreateResponse(HttpStatusCode.OK);
result.Content = new ByteArrayContent(data);//here data is byte[]
var name = data.Name.ToLower().Contains(data.DocType.ToLower())
? data.Name
: $"{data.Name}{data.DocType}";
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("inline")
{
FileName = name
};
result.Content.Headers.ContentType = new MediaTypeHeaderValue(MimeMapping.GetMimeMapping(name));
//here i am setting up the headers content type for example 'text/application-json'
return result;
}
希望对大家有所帮助。