[英]how to bypass pop-up blocker in angular 6?
我想在單擊預覽按鈕時顯示 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 並想在新窗口中顯示但瀏覽器阻止彈出的方式
下面的代碼將幫助您打開附件(新窗口中的文件)而不會彈出阻止程序
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
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.