Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

179
Vistas
How to put the response of a post-request into a new window/tab

I have this working example of how to use POST and put the server-generated html in a new window:

const response = await this.axiosInstance.post(url, postData)
const htmlResponse = response.data
const newWindow = window.open()
newWindow.document.write(htmlResponse)

However I'm not sure if this is the best or even correct way to do it. I see a few warnings with this. I get a warning on the last line that newWindow is possibly 'null'. If switching to TypeScript I am also not sure the type of htmlResponse. I would assume Document, but write() only supports string, so it might be the correct classification.

Is there a better way to put the content of a post-request into a new window?

Update: The content-type is of type text/html; charset=UTF-8, not sure if it changes anything.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

What you have there might be enough for your use case. One might recommend waiting for some form of a ready event before manipulating the DOM.

const newWindow = window.open();
newWindow.onload = (event, f, g, h) => newWindow.document.write('Do great things.');

A much better solution might be fetching actual data instead of an HTML string from the server, creating a template page to receive the data, and rendering a well-formatted page.

The Window.postMessage() API could be used to send data between parent and child windows. This is especially useful if you need to circumvent the Same-origin policy.

I have made several assumptions, and this suggestion might not work for your use case.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda