Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

197
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!