Prashobh
Prashobh

Reputation: 9542

How to Download a pdf Using the response from service

my code

var url = getApplicationRoot() + '/api/dossier/report/pdfReport?reportId='+reportid;
            console.log(url);
            $http.get( url, {cache: false} )
            .success( function( data )
            {
                //success(data);
                console.log(data);
                if(success){
                    window.open( getApplicationRoot() + '/api/dossier/report/pdfReport?reportId='+reportid);
                }
            })

I am able to download as pdf ,but its opening in another window and downloading because i given window .open .How can i make in the same window .As like normal download . I am using angular MVC .

Firfox it is working fine .But in Chrome it is opening in new window

Upvotes: 0

Views: 718

Answers (3)

Laura
Laura

Reputation: 1602

Just add '_self' as a second parameter to window.open().

window.open(getApplicationRoot() + '/api/dossier/report/pdfReport?reportId=' + reportid, '_self');

Upvotes: 1

Andrei
Andrei

Reputation: 4617

I used this jQuery plugin from Filament Group to do something similar: https://github.com/filamentgroup/jQuery-File-Download

Upvotes: 0

QuarK
QuarK

Reputation: 2536

Instead of using window.open(...) you can use an iframe or the window.location:

// iframe
var ifrm = document.getElementById(frame);
ifrm.src = getApplicationRoot() + '/api/dossier/report/pdfReport?reportId='+reportid;

// in the same window
window.location=getApplicationRoot() + '/api/dossier/report/pdfReport?reportId='+reportid;

Upvotes: 1

Related Questions