【问题标题】:Get access denied for PDF bypassSecurityTrustResourceUrl on Edge browser在 Edge 浏览器上拒绝访问 PDF bypassSecurityTrustResourceUrl
【发布时间】:2018-09-17 20:19:36
【问题描述】:

当前行为

无法打开 PDF 文件,bypassSecurityTrustResourceUrl 在 Edge 浏览器上拒绝访问 PDF

预期行为

应该查看 PDF 文件

用说明最小化重现问题

这一行产生了问题

<object  [data]="pdfURL | safeUrl" > </object>

这条线工作正常 如果 PDF URL 已经写在 html 中,它就可以工作

<object  data="https://pdfobject.com/pdf/sample-3pp.pdf" > </object>

这是 safeUrl 管道

@Pipe({ name: 'safeUrl'})
export class SafeUrlPipe implements PipeTransform  {
  constructor(private sanitized: DomSanitizer) {}
  transform(value) {
    return this.sanitized.bypassSecurityTrustResourceUrl(value);
  }
}

环境

Angular CLI: 6.1.1
Node: 8.11.3
OS: win32 x64
Angular: 4.4.7
... animations, common, compiler, compiler-cli, core, forms
... http, platform-browser, platform-browser-dynamic
... platform-server, router, tsc-wrapped


Browser:
- [x ] Edge version Default

For Tooling issues:
- Node version: XX  <!-- run `node --version` -->
- Platform:  Windows 

【问题讨论】:

    标签: angular pdf microsoft-edge


    【解决方案1】:

    根据PDF Viewer using object tag not working for Edge

    我们需要使用 DOM elementRef 设置数据属性。

    模板:

    <object [data]="pdfurl | safeUrl" #pdfobject></object>
    

    组件:

    @ViewChild('pdfobject') pdfobject: ElementRef;
    this.pdfobject.nativeElement.setAttribute('data', 'https://pdfobject.com/pdf/sample-3pp.pdf');
    

    【讨论】:

    • 对不起,有时间我会测试它,如果有人测试它,我会确认答案。谢谢
    猜你喜欢
    • 1970-01-01
    • 2016-05-23
    • 1970-01-01
    • 2013-01-17
    • 2019-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多