Force IE open download in a new window

I have a web application that lists the files stored inside it.

Each element has a hyperlink, which, when clicked on it, opens the "Open / Save" dialog box.

Now, if I click on the link pointing, say, to a Word document and select "Open", it will open in its own window, as expected. However, if the file is an HTML file, and I select the Open option, it opens to the page in the browser [correctly], but it opens in the window that I used to select the document [bad].

So, to the question: is it possible to forcefully open the "Open" dialog box of the "Open / Save" dialog box to open a document in a new window?

Edit: A hyperlink that forces you to open a document is not just a pointer to a file (for a number of reasons). The .NavigateUrl property contains a JavaScript function call. This function makes an Ajax request to the correct application, which retrieves the document from the secure store and presents it to the user's browser as an attachment (Content-Disposition: attachment)

Further editing: The JavaScript function simply returns an Ajax call to the page. The result of this action is to display the page in an IFrame. This page is written directly to the response object as follows:

Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", String.Format("attachment;filename=\"{0}\"", FileName)); Response.AddHeader("Content-Length", String.Format("{0}", length)); Response.Flush(); Response.Close(); 

I believe that if you can change the action of the Open button in the Open / Save dialog box that appears, this will be what I am doing in this code that will force it.

If that matters, this is a .Net v4.0 application written in C #.

I know about the good and bad opening of new windows, but this is a private application, and this is what the client wants.

+4
source share
1 answer

Instead of each link pointing to a JS function on the base page, try doing this ...

Provide each URL link (for example, / GetFileContent.aspx? Fileid = 123) and complete this page before downloading the file. Save your ContextType header code and response as it is.

Each link will open a new window and will look something like this:

 <a href="/GetFileContent.aspx?file=123" target="_blank">filename.doc</a> 
+5
source

Source: https://habr.com/ru/post/1380405/


All Articles