0

I am downloading the file from the server using API, for that i have to send session details in header, how can i do it using angularjs?. Please help me out.

Thank you in advance for suggestions.

Vinayak Shedgeri
  • 2,222
  • 1
  • 21
  • 24
  • 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:40

2 Answers2

3

No - It is not possible to send headers in straight way using $window.open

Yes - Its is possible but not straight way, If you've got server-side control then you can set header value in query string and get it parsed from query string on the back-end.

Zeeshan Hassan Memon
  • 8,105
  • 4
  • 43
  • 57
2

I don't suggest to pass params with window.open.

BUT you can use window.open like this.

var params = {
 access_token: 'An access_token',
 other_header: 'other_header'
};

//Add authentication headers in URL
var url = [url_generating_pdf, $.param(params)].join('?');

//Open window
window.open(url);

Please check the details info here

Vishal Sharma
  • 1,372
  • 1
  • 8
  • 17
  • Nope, didn't work for me. This just appends the values I want in my header into the URL string. It's not the same thing. – Mike Gledhill Feb 15 '18 at 09:19
  • Do not put tokens in URL- that's insecure https://stackoverflow.com/a/46141515/4233629 – Sush May 16 '19 at 19:41