iframe可以识别将网址转换为安全网址链接

时间:2019-05-29 13:36:30

标签: javascript angular

如何将网址转换为iframe可以识别的安全网址链接

  <iframe src="{{url}}"></iframe>

1 个答案:

答案 0 :(得分:0)

在下面尝试这样

secure-pipe.ts

import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer} from '@angular/platform-browser';

@Pipe({ name: 'secure' })
export class SecurePipe implements PipeTransform {
  constructor(private sanitizer: DomSanitizer) {}
  transform(url) {
    return this.sanitizer.bypassSecurityTrustResourceUrl(url);
  }
} 

app.module.ts

@NgModule({
   declarations : [
     ...
     SecurePipe
   ],
})

以HTML格式

<iframe [src]="url | secure"></iframe>