首页 > 解决方案 > 拒绝在框架中显示“URL”,因为它将“X-Frame-Options”设置为“sameorigin”以显示 PDF

问题描述

我参考了https://angular.io/guide/security#xss并尝试在我们的 Intranet sharePoint 网站上的网页上显示 PDF

这是模板:help.component.html:

<iframe class="e2e-iframe-trusted-src" width="640" height="390" [src]="trustedUrl" ></iframe>

和组件:help.component.ts

import { Component, OnInit } from '@angular/core';
import { SessionResetService } from '../../services/session-reset.service';
import { DomSanitizer, SafeUrl } from '@angular/platform-browser';

@Component({
  selector: 'app-help',
  templateUrl: './help.component.html',
  styleUrls: ['./help.component.scss']
})
export class HelpComponent implements OnInit {
    public trustedUrl: SafeUrl;
    public helpUrl: string;
    constructor(private _resetSession: SessionResetService,
        private sanitizer: DomSanitizer) {
        this.helpUrl = "https://website Url/Tool.pdf";
        this.trustedUrl = this.sanitizer.bypassSecurityTrustResourceUrl(this.helpUrl);
    }

    ngOnInit() {
        this._resetSession.CallResetSession();
  }
}

我尝试按照建议附加 &embedded=true: How to fix Refused to display in a frame because it set 'X-Frame-Options' to 'sameorigin

但这也不起作用。请指导

标签: angulariframeangular-dom-sanitizer

解决方案


推荐阅读