我想在单击预览按钮时显示pdf,但是在新标签页中打开时pdf被阻止了。所以,我想通过浏览器的弹出窗口阻止程序属性
getPdf(projectId) {
this.http.get(environment.apiUrl + "/poject/getPdf/" + projectId + '/' + this.userDataSession.userDetailsId + '/' + 8 + '/' + this.authService.getUserToken(), { responseType: 'blob' })
.subscribe((blob: Blob) => {
let url = URL.createObjectURL(blob);
let link = document.createElement("a");
if (link.download !== undefined) {
let url = URL.createObjectURL(blob);
let win = window.open(url, '_blank');
win.focus();
link.style.visibility = 'hidden';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
});
}
这是我从服务器访问pdf并希望在新窗口中显示但浏览器阻止弹出窗口的方式
答案 0 :(得分:0)
下面的代码将帮助您打开附件(新窗口中的文件)而不会弹出阻止程序
getPdf(projectId) {
let newWindow = window.open();//OPEN WINDOW FIRST ON SUBMIT THEN POPULATE PDF
this.http.get(environment.apiUrl + "/PROJECT/getPdf/" + projectId + '/' + this.userDataSession.userDetailsId + '/' + 9 + '/' + this.authService.getUserToken(), { responseType: 'blob' })
.subscribe((blob: Blob) => {
let file = new Blob([blob], { type: 'application/pdf' });
let url = URL.createObjectURL(file);
this.router.navigate([url]);
newWindow.location.href = url;//POPULATING PDF
});
}