0

I have a window.open command like this:

window.open("http://MyServer/MyPage");

And I know that I can set accepts of a request, using something like this:

var client = new XMLHttpRequest();
client.open("GET", "http://MyServer/MyPage");
client.setRequestHeader("Accept", "ContentTypeName");
client.send();

Now I need to combine this two things. But I don't know how. So...

How can I set accepts in HTTP header to a call executed by a window.open command?

UPDATED
Here is a very similar question to that: window.open with headers.
And is already answered.

But as the answer suggests I write in my new window, will be not possible if my content type is a binary like:

  • application/pdf
  • application/vnd.ms-excel
  • application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

That for my needs these types will be present. So anyone know how I can do it?

Community
  • 1
  • 1
Jonny Piazzi
  • 3,684
  • 4
  • 34
  • 81
  • What you COULD do is to document.write the result of an AJAX call (with request headers set) to the new window – mplungjan Mar 08 '15 at 16:21
  • Because my content type in many cases is excel or pdf and I can't write this. – Jonny Piazzi Mar 08 '15 at 16:24
  • Why not request `/?format=pdf` or /pdf/... and have the server generate the content type? – mplungjan Mar 08 '15 at 16:25
  • Yeah it's possible, but just for curiosity, I want to know if it's possible using accepts parameter. – Jonny Piazzi Mar 08 '15 at 16:30
  • The computer says no... [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Window/open) [MSDN](https://msdn.microsoft.com/en-us/library/windows/apps/hh453415.aspx) – mplungjan Mar 08 '15 at 16:33
  • I edited the question, can you re-evaluate the duplicate markup? – Jonny Piazzi Mar 08 '15 at 16:43
  • The answer is still `not possible` - however in some browsers you were able to pass the mime type to the document.open, so in principle you could try: `var win=window.open(); win.document.open("application/excel"); win.document.write(excelData); win.document.close()` – mplungjan Mar 08 '15 at 16:55

0 Answers0