简体   繁体   English

如何使用服务响应下载pdf

[英]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 . 我能够以pdf格式下载,但可以在另一个窗口中打开并下载,因为我给定了window.open。如何在同一窗口中进行制作。就像普通下载一样。 I am using angular MVC . 我正在使用角度MVC。

Firfox it is working fine .But in Chrome it is opening in new window Firfox工作正常。但是在Chrome中,它在新窗口中打开

Instead of using window.open(...) you can use an iframe or the window.location: 除了使用window.open(...),还可以使用iframe或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;

只需将'_self'作为第二个参数添加到window.open()

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

我使用了来自Filament Group的jQuery插件来做类似的事情: https : //github.com/filamentgroup/jQuery-File-Download

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM