How can I prevent IE10/IE11 from displaying the open or save prompt?

Currently, I am utilizing JavaScript blob to download files from the server as shown below:

let blob = new Blob([resposne['_body']], { type: contentType });
if (navigator.msSaveBlob) {
    navigator.msSaveOrOpenBlob(blob, fileName); // applicable for IE
} else {
    let objectUrl = window.URL.createObjectURL(blob);
    window.open(objectUrl);
}

Although the code functions properly, Internet Explorer displays a dialog:

https://i.sstatic.net/carV0.png

Furthermore, if a direct PDF link is placed inside the href tag, it works without any issues. This indicates that there may not be an issue with the Adobe plugin.

The ultimate goal is to have the file open directly without displaying the prompt. I attempted to use a Registry hack recommended here, but it did not produce the desired outcome. Any suggestions on how to achieve this?

Answer №1

If you're struggling with a similar issue, I managed to resolve it by utilizing the window.open function. Instead of downloading the response, I directly provide the URL to window.open in this manner:

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

Keep in mind that the API should return the stream response with the header type set. In my scenario, the C# web API method looked like this:

public HttpResponseMessage Download(int id)
{
   var data = _service.Download(id);
   HttpResponseMessage result = null;
   result = Request.CreateResponse(HttpStatusCode.OK);
   result.Content = new ByteArrayContent(data); // where data is a 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;
}

Hopefully, this solution will be beneficial to someone facing a similar challenge.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ensure that you wait for all asynchronous $http requests to finish in AngularJS before continuing

I am facing a challenge with a page that generates a varying number of $http requests based on the length of a certain variable. I aim to update the scope with the data only after all requests have been completed. Without relying on jQuery for this project ...

How can you connect templates to actions and models in AngularJS directives?

I am currently working on building a custom directive that has presented me with two challenges. Take a look at the template provided below... restrict: 'A', require: '?ngModel', template: '<div>' + ' ...

What is the most effective method for declaring callbacks on objects in Typescript?

I am currently working on a sidebar menu component that is connected to a service holding items in the menu. This allows multiple sources to make alterations to the menu as needed. Each item in the menu currently follows the SidebarItem interface: export ...

The UI-date timepicker in Angular JS does not allow the timepicker box to be closed by clicking on the input

Trying out the uidatetimepicker simple demo In this demo, I have customized it by eliminating the clock icon and adding an ng-click action to the input field. I want the input to not only open the time form but also close it upon a certain action: First ...

Modify the appearance of certain text within an input field

I need some help adding style to specific text within an input field. For example, if the user types in "Hello world" and the special text is "world" I want to achieve this result: https://i.sstatic.net/Ozd6n.png This is what my HTML code looks like: & ...

Whenever I attempt to implement NavigationContainer in react native, an error always pops up

Hey there! I'm currently diving into the world of React Native and decided to start with a small project. However, I've encountered a persistent error when trying to use the NavigationContainer. Here's the error message I keep getting: error ...

Incorporate a CSS-styled Hyperlink Button into a Jquery Loopedslider

After spending the last 2 hours trying to figure out what seems to be a simple solution, I am determined to add a hyperlink button to each image/div in the jquery Loopedslider using CSS. Although I have used loopedslider multiple times before, I have neve ...

The angular framework is unable to assign a value to the property 'xxxx' because it is currently undefined

I am currently working on a simple application using Ionic (angular) and I am facing an issue with the error message: Cannot set property 'origin' of undefined Below is the interface for Product.ts: export interface Products{ id: number ...

How to Use PHP to Submit Form Information

I am a beginner in PHP and I need help with sending form details to an email address. I have tried looking for solutions online but I keep running into the same issue - when I submit the form, it downloads the PHP file instead of sending an email. Below i ...

Having trouble loading a CSV file into a static folder using Node.js and Express

As a newcomer to node and express, I am exploring the integration of d3 visualizations into my web page. Essentially, I have a JavaScript file that creates all the d3 elements, which I then include in my .ejs file. I am currently attempting to replicate a ...

The website is having trouble reading the local json file accurately

Currently, I have developed an HTML site that utilizes JavaScript/jQuery to read a .json file and PHP to write to it. In addition, there is a C++ backend which also reads and writes to the same .json file. My goal is to transmit the selected button informa ...

Error: The "checkAvailability" method is not available in the model object

When attempting to implement some functionality methods for my model, I encountered an issue where sending a request resulted in the following traceback: /home/nano/Dev/JS/OMI/node_modules/mongoose/lib/utils.js:413 throw err; ^ TypeE ...

Receiving a 200 ok status, but encountering a response error in Postman

Receiving a response with a 200 OK status, but encountering an error message in Postman. { "errors": "Unable to log you in, please try again.", "success": false } Post Url: [{"key":"Content-Type","value":"application/json","descript ...

Typescript PDFjs encountering loading issues with corrupt files

In my Vue.js application, I have the following TypeScript class: /** Taken from https://github.com/VadimDez/ng2-pdf-viewer/blob/master/src/app/pdf-viewer/pdf-viewer.component.ts */ import { Component, Vue } from 'vue-property-decorator'; import ...

Unveiling the magic behind using jasmine to spy on a generic

I am trying to spy on a generic method in TypeScript, but Jasmine is not recognizing it. Here is the code snippet: http: HttpClient <- Not actual code, just showing type. ... this.http.get<Customer[]>(url); In this code, I am trying to mock the ...

What is the best way to access a particular property of an object?

Currently, I am successfully sending data to Mongo and storing user input information in the backend. In the console, an interceptor message confirms that the data is received from MongoDB. However, I am struggling to extract specific properties such as th ...

What is the most effective method for configuring an npm module?

I need help with configuring an npm module that I'm developing. The module includes two functions called notify.sms.send() and notify.email.send(), as well as an abstract function notify.send() that can call either or both of these functions. To hand ...

When an Angular service is created, its properties are not immediately configured

My current task involves testing an Angular (4.1) service that looks like this: @Injectable() export class JobService { private answerSource = new Subject<AnswerWrapper>(); answer$ = this.answerSource.asObservable(); answer(answer: AnswerWra ...

Retrieving data arrays from response.json

I've been on a wild goose chase trying to solve this puzzling issue. RAWG has transitioned to using their own API instead of Rapid API for game reviews, and I'm in need of data for "Tom Clancy Rainbow Six Siege". Despite my efforts to convert t ...

Identifying IPV6 Private and Loopback Addresses in Node.js: A Guide

Right now, I am looking for a way to distinguish between private addresses and web reachable ones. I am seeking a method to test for the following: Given a list of ipv6 addresses on an interface, I need to identify which ones are web reachable. It's ...