Is there a way to prevent IE10 / IE11 from showing open or saved tooltip

I am uploading files from server using javascript blob, something like

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);
}

      

The code above works fine, but in IE it shows a dialog:

prompt

Also, if I put the direct pdf link in the href tag, then it works fine too. So it looks like there is no problem with the adobe plugin.

I just want to open the file and not show this prompt. I tried a registry hack as suggested here , but no luck. Any ideas how to do this?

+3


source to share


1 answer


For those who are facing the same problem, I solved it using window.open

. Instead of downloading the response, I directly pass the url window.open

to something like

window.open(apiUrl) // Exmp "host:api/documents/download?id=1"

      

Note: -API must return a stream response with the header type set. In my case, the C # web API method was



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;
}

      

Hope this helps someone.

+2


source







All Articles