【问题标题】:how to parse url from iframe code in angular如何以角度从iframe代码解析url
【发布时间】:2021-04-02 17:52:02
【问题描述】:

我有一个 youtube iframe 代码。

<iframe width="560" height="315" src="https://www.youtube.com/embed/zfpmc-NnjXQ" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

我怎样才能只打印来自该 iframe 代码的 url 角度。

请帮忙。

【问题讨论】:

  • 恐怕我们需要更多的上下文和解释。这个 iframe 是否已经在您的视图中?如果它在您的视图中,那么您已经拥有该 URL。如果不是,那么它在哪里?另外print only url 是什么意思?请花时间写一个正确的问题。

标签: javascript jquery angular iframe


【解决方案1】:

试试这样的:

在ts文件中:

import { Component } from '@angular/core';
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';
@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ]
})
export class AppComponent  {
  name = 'Set iframe source';
  url: string = "https://www.youtube.com/embed/zfpmc-NnjXQ";
  urlSafe: SafeResourceUrl;

  constructor(public sanitizer: DomSanitizer) { }

  ngOnInit() {
  this.urlSafe= this.sanitizer.bypassSecurityTrustResourceUrl(this.url);
 }
}

在 html 文件中:

<hello name="{{ name }}"></hello>
 <div style="text-align:center">
  <h1>Reports</h1>
 </div>

<iframe width="560" height="315" frameBorder="0" [src]="urlSafe"></iframe>

更多详情:here

【讨论】:

  • 感谢您的回答。如何动态地将 url 与 iframe 分开?
  • 你真正的意思是什么?请说清楚一点。
猜你喜欢
  • 2020-02-17
  • 1970-01-01
  • 2021-11-22
  • 2023-03-11
  • 1970-01-01
  • 2018-01-22
  • 1970-01-01
  • 2016-01-05
  • 2019-11-19
相关资源
最近更新 更多