Can I control the HTTP headers sent by window.open (cross browser)?

No

If not, can I somehow window.open a page that then issues my request with custom headers inside its popped-up window?

  • You can request a URL that triggers a server side program which makes the request with arbitrary headers and then returns the response
  • You can run JavaScript (probably saying goodbye to Progressive Enhancement) that uses XHR to make the request with arbitrary headers (assuming the URL fits within the Same Origin Policy) and then process the result in JS.

I need some cunning hacks...

It might help if you described the problem instead of asking if possible solutions would work.

Answer from Quentin on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › Window › open
Window: open() method - Web APIs | MDN
These features include options such as the window's default size and position, whether or not to open a minimal popup window, and so forth. The following options are supported: ... Indicates that you want the browser to send an Attribution-Reporting-Eligible header along with the open() call.
Discussions

Add support to the window.open function for the Accept header.
Problem: Currently the window.open() function does not support passing in the Accept header. Sample use case: If i would like to make a GET request in a new browser window and ask the server via th... More on github.com
🌐 github.com
9
February 12, 2022
How to open a link in new window with a header? - CSS-Tricks
I have some links and I want when I click on them , open up in a new window with a header bar containing some text or images like some template centers which show their templates’ demos and you can change template through a header and it’s always static. More on css-tricks.com
🌐 css-tricks.com
April 2, 2013
angularjs - how to add authentication header to $window.open - Stack Overflow
I have angularjs application where users enter data that is saved to database, then on server side it is compiled into pdf file. All access requires appropriate authentication headers in place. After More on stackoverflow.com
🌐 stackoverflow.com
angularjs - is that possible to send header information in $window.open(url) method - Stack Overflow
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. ... I don't suggest to pass params with window.open. More on stackoverflow.com
🌐 stackoverflow.com
🌐
Medium
medium.com › @mkushwah222 › javascript-pass-headers-in-window-open-c1e841640049
JavaScript: Pass headers in window.open() - Mohit Kushwah - Medium
November 18, 2022 - export const viewFile = async (url, headers) => { fetch(url, { method: ‘GET’, headers }) .then((res) => res.blob()) .then((blob) => { var _url = window.URL.createObjectURL(blob); window.open(_url, “_blank”).focus(); }) };
🌐
GitHub
github.com › whatwg › html › issues › 7810
Add support to the window.open function for the Accept header. · Issue #7810 · whatwg/html
February 12, 2022 - Problem: Currently the window.open() function does not support passing in the Accept header. Sample use case: If i would like to make a GET request in a new browser window and ask the server via th...
Author   reallybaldrick
🌐
CSS-Tricks
css-tricks.com › forums › topic › how-to-open-a-link-in-new-window-with-a-header
How to open a link in new window with a header? - CSS-Tricks
April 2, 2013 - I have some links and I want when I click on them , open up in a new window with a header bar containing some text or images like some template centers which show their templates’ demos and you can change template through a header and it’s always static.
Find elsewhere
🌐
freeCodeCamp
forum.freecodecamp.org › t › window-open-vs-get › 169384
Window.open() vs $.get()
August 4, 2017 - Hi, I am running a few tests for my Quote Machine Challenge App. Besides Twitter, I’d linke to share the quotes as well to Hubzilla. Running window.open(hubzillaQueryLink) will open a new window and post fine according to the queryString. Now I thought I might want to get the JSON that’s put in the newly opened window and extract the Hubzilla Site where the quote is actually posted, so you don’t see a JSON but the actual network you are posting to.
🌐
Pega
support.pega.com › question › send-custom-http-header-through-open-url-window-action
Send custom HTTP header through 'Open URL in Window' action | Support Center
February 25, 2016 - Since I think Pega 7.1.8 does not have a OOTB way to send custom HTTP headers... Any idea for a workaround for this problem? ... Copy link Copying... Copied! ... Instead of using action “Open URL in Window”, we've added action Run Activity. This activity sets the required parameters and then does a Show-HTML.
🌐
GitHub
github.com › nwjs › nw.js › issues › 3208
How to get http headers from opened window? · Issue #3208 · nwjs/nw.js
September 3, 2015 - var win = gui.Window.open('https://github.com',); Can i get the http response headers from github? if so, how? Thank you · No one assigned · No labels · No labels · No type · No projects · No milestone · None yet · No branches or pull requests ·
Published   Mar 09, 2015
🌐
YouTube
youtube.com › watch
JavaScript : window.open with headers - YouTube
Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.
Published   April 29, 2019
🌐
GitHub
github.com › IdentityModel › oidc-client-js › issues › 569
Question: pass authorization headers in Window.open, iframe scenarios · Issue #569 · DuendeArchive/identity-model-oidc-client-js
December 30, 2017 - Our UI is built on angularJS and we have some applications that were included in iframe's that were built in MVC and asp.net forms (for the some of the SQL SEREVER reportviewer limitations). This is all used to work with cookie based authentication. But after we switch to Identity provider, all these end points are expecting authorization headers and since we can not pass auth headers to iframes or window.open, This functionality is breaking.
Published   May 30, 2018
Author   vejandla
🌐
Stack Overflow
stackoverflow.com › questions › 42106744 › how-to-add-request-headers-to-window-open-in-javascript
c# - How to add request headers to window.open in javascript? - Stack Overflow
The url for the window.open contains my controller name and action method so that it will hit the respective action method. But due to some reason, when I run with http request, I'm able to open the pdf, which means my controller call returns 200. But in the case of https, my controller throws a 302. Is there any solution for this? One more thing which I found out is, when I compose the https request in Fiddler by adding some request headers to it, my controller returns 200.
🌐
Dasith
dasith.me › 2019 › 04 › 29 › protecting-assets-without-using-authorization-headers
Protecting Assets Without Using Authorization Headers (i.e. Bearer Tokens)
August 19, 2020 - private urlClicked(string attachmentId): void { this.getAttachmentUrl(this.attachment.id) .subscribe(url => { window.open(url); // caution: popup blockers might prevent this }); } private getAttachmentUrl(attachmentId: string): Observable<string> { const tokenUri = `api/attachment/token/${attachmentId}`; const headers = new HttpHeaders({ 'Content-Type': 'application/json' }); headers.append('Authorization', auth_token); // or let your interceptor add it return this.http.get<string>(tokenUri, { headers: this.headers }).pipe(map( token => `api/attachment/download/${token}`)); }
🌐
CopyProgramming
copyprogramming.com › howto › how-to-add-authentication-header-to-window-open
Angularjs: Adding an authentication header to the window open function: A guide
May 9, 2023 - In such cases, it is advisable to present a secondary button that allows users to initiate the download once it is complete. This can be achieved by calling window.open from the second button. Java - How to add Header with Authorization for, Adding parameter definition to a custom OpenAPI bean will not work because the parameter won't get propagated to the operations definitions.
🌐
Itecnote
itecnote.com › tecnote › javascript-window-open-with-headers
Javascript – window.open with headers
January 9, 2022 - Skip to content · React-native – React Native Error: “Animated.event now requires a second argument for options” · Python – keep on getting “x and y must have same first dimension, but have shapes (100,) and (1, 100)” · Java – Docker WARNING: Published ports are discarded when ...