加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

如何使用angular2 rc.6在显示pdf的embed html标签上禁用sanitize

发布时间:2020-12-17 17:01:51 所属栏目:安全 来源:网络整理
导读:我真的不明白我在做错了什么: 模板: embed [src]="pdfUrl" width="500" height="100%" type='application/pdf' 类: pdfURL;constructor(private domSanitizer : DomSanitizer) {}ngOnInit() { this.pdfUrl = this.domSanitizer.bypassSecurityTrustUrl('h
我真的不明白我在做错了什么:

模板:

<embed [src]="pdfUrl" width="500" height="100%" type='application/pdf'>

类:

pdfURL;
constructor(private domSanitizer : DomSanitizer) {}
ngOnInit() {
    this.pdfUrl = this.domSanitizer.bypassSecurityTrustUrl('http://example.com/pdf.pdf')
}

这实际上不会加载< embed>但不会抛出错误.

我在pdfURL和bypassSecurityTrustResourceUrl()上使用SafeUrl类型尝试了它.
<嵌入>标签收到正确的URL但没有显示任何内容.

解决方法

我认为它应该是:

this.pdfUrl = this.domSanitizer.bypassSecurityTrustResourceUrl('url')

并使用它像:

<iframe [src]="pdfUrl" width="500" height="600" type='application/pdf'></iframe>

见Plunkr

更新(Chrome中的嵌入代码存在错误)

对于embed标记,您可以通过outerHTML重新注入embed标记:

this.renderer.setElementProperty(el,'outerHTML',el.outerHTML)

对于这种情况,请参见plunker

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读