2

This answer here says I can't pass headers while using window.open. Although I couldn't find any documentation stating this.

Is it really not possible to do so. Are there any possible hacks ?

My client requests are sent to a server which I can't control. The request sent by browser for opening pdf (window.open) is received at that server without auth headers. Hence, user is prompted for username and password.

Is there a way I can resolve my issue and be able to open pdf from my Angular application. I would also like to know how window.open works internally as I could not find it online ?

Thanks in advance

Saurabh Tiwari
  • 4,632
  • 9
  • 42
  • 82
  • The spec does not give any clue that this is intended, though query parameters are also some kind of header... https://www.w3schools.com/jsref/met_win_open.asp – Mijago Aug 25 '17 at 06:53
  • Possible duplicate of [window.open with headers](https://stackoverflow.com/questions/4325968/window-open-with-headers) – Mijago Aug 25 '17 at 06:56
  • 1
    I do not have access to server, hence cannot use above solutions – Saurabh Tiwari Aug 25 '17 at 12:21
  • There is an open issue for adding support for headers to the window.open function in the HTML standard. Please voice your opinions and needs on there. [https://github.com/whatwg/html/issues/7810](https://github.com/whatwg/html/issues/7810) – Dan Apr 14 '22 at 21:35

1 Answers1

-1

I was able to solve the problem by getting the file twice, once from the server and once from cache. This required a Cache-Control header on the response. I'm working with Angular, AdalJS, and Web Api but this might apply more broadly.

I use a $http call with auth header added by AdalJS to securely retrieve the file. This response is cached by the browser. When complete, I use window.open to open the cached file.

Pop-up blocking can be a problem. If you can't disable blocking, consider displaying a second button to click when the download is complete, calling window.open from that.

BillVo
  • 565
  • 1
  • 5
  • 20