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

798
Views
Opening a PDF Blob in a new Chrome tab (Angular 2)

I am loading a PDF as follows (I am using Angular 2, but I am not sure that this matters..):

//Inside a service class
downloadPdf = (id): Observable<Blob> => {
    let headers = new Headers();
    headers.append("Accept", "application/pdf");
    return this.AuthHttp.get(this.pdfURL + id, {
        headers: headers,
        responseType: ResponseContentType.Blob
    }).map(res => new Blob([res.blob()], {type: "application/pdf"}));
}

//Inside a click handler
this.pdfService.downloadPdf(this.id).subscribe((data: Blob) => {
        let fileURL = window.URL.createObjectURL(data);
        window.open(fileURL);
    });

This code runs nicely in Firefox. In Chrome, a new tab briefly flashes open and closes. When I debug and I manually put surf to the object URL, Chrome can open it just fine.

What am I doing wrong here?

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

The opening of a new tab got blocked by an adblocker.

about 4 years ago · Santiago Trujillo Report

0

It can not work, new popup will be blocked by browser, because of it was created from callback which is not a trusted event, to make it work it must be called directly from click handler, or you have to disable bloking popups in your browser.

Chrome will only allow this to work as wanted if the ajax call returns in less than a second. More there

about 4 years ago · Santiago Trujillo Report
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!