簡體   English   中英

如何使用服務響應下載pdf

[英]How to Download a pdf Using the response from service

我的代碼

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);
                }
            })

我能夠以pdf格式下載,但可以在另一個窗口中打開並下載,因為我給定了window.open。如何在同一窗口中進行制作。就像普通下載一樣。 我正在使用角度MVC。

Firfox工作正常。但是在Chrome中,它在新窗口中打開

除了使用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