如何绕过角度6中的弹出窗口阻止程序? [英] how to bypass pop-up blocker in angular 6?

查看:75
本文介绍了如何绕过角度6中的弹出窗口阻止程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在单击预览按钮时显示pdf,但是在新标签页中打开时pdf被阻止了.所以,我想通过浏览器的弹出窗口阻止程序属性

i want to show pdf on clicking preview button but pdf is blocked while opening in a new tab .. So , I want to by pass pop-up blocker property of browsers

     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并希望在新窗口中显示但浏览器阻止弹出窗口的方式

This is how i am accessing pdf from server and want to show in a new window but browser is blocking the pop up

推荐答案

下面的代码将帮助您打开附件(新窗口中的文件),而不会弹出阻止程序

Below code will help you to open attachment(file in new window) without pop up blocker

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

这篇关于如何绕过角度6中的弹出窗口阻止程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆