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

199
Vistas
open pdf in browser using javascript xmlhttprequest

So I've looking around a lot and try to see best way to open blob as pdf in browser. Closest stackoverflow question i was able to find was this one: XMLHttpRequest to open PDF in browser but this is 11 years old. Currently I have a program that looks like this:

var xhr = new XMLHttpRequest();
  xhr.open('GET', 'http://localhost:8080/api/download', true);
  xhr.responseType = 'blob';
  
  xhr.onload = function(e) {
    if (this.status == 200) {
      // Note: .response instead of .responseText
      var blob = new Blob([this.response], {type: 'application/pdf'}),
          url = URL.createObjectURL(blob);
          window.open(url, '_blank');     
    }
  };
  xhr.send();

Now again Issue here is that it opens in chrome browser ( FYI: Version 102.0.5005.61 (Official Build) (arm64)) with a UUID. So url of new tab looks something like this:

blob:http://localhost:3000/f7c5571a-bf59-45d1-99ea-e495fe859008

Now when I click on download icon. File explorer opens up with UUID in it and I cannot download it in windows. When I try it says network error.

Question: What is best possible way to display just pdf in browser. While removing downloading icons if they are not going to work.

Oh i have also tried creating the link and then doing link.download = fileName; That works perfectly fine but I am not looking to download file just view it on browser. I have also tried content-disposition inline and attachment. Does not work. Result is same.

Thanks a lot!

about 4 years ago · Juan Pablo Isaza
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