javascript - Angular 5 阻止 iframe 谷歌地图

标签 javascript angular google-maps iframe xss

我有以下 iframe

<iframe
  width="600"
  height="450"
  frameborder="0" style="border:0"
  [src]="mapsurl" allowfullscreen>
</iframe>

mapsurl 是安全 URL (https)

我收到以下错误:

ERROR Error: unsafe value used in a resource URL context (see http://g.co/ng/security#xss) at DomSanitizerImpl.webpackJsonp.../../../platform-browser/esm5/platform-browser.js.DomSanitizerImpl.sanitize

我检查了一些资源。 Angular 文档像往常一样令人难以忍受。我正在继续研究,将用调查结果编辑问题。最好有任何帮助。

最佳答案

使用DomSanitizer

   import { DomSanitizer } from '@angular/platform-browser';

   constructor(public sanitizer: DomSanitizer){}

然后在 HTML 中:

    <iframe [src]='sanitizer.bypassSecurityTrustResourceUrl(mapsurl)'  width="600"
  height="450"
  frameborder="0" style="border:0"
  allowfullscreen>
    </iframe>

关于javascript - Angular 5 阻止 iframe 谷歌地图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49958826/

相关文章:

javascript - React Native - 如何在返回上一页时刷新 FlatList?

javascript regex .match 在某个字符串处停止

angular - 可选择的表格行并将选择信息传递给新组件

javascript - 如何为 *ngIf 内声明的模板调用 @ViewChild?

pagination - ng2-bootstrap pagination pageChanged 触发多次

php - 谷歌地图、PHP 和 MySQL : Create multiple markers on map using various options together

java - 将 Google map 添加到 fragment

javascript - 使用 jquery 将特定单词(字符串)大写

javascript - 使用 javascript 将视频上传到 facebook,无需 php

将 GMSPolygon 或 GMSPolyline 添加到 map 时,iOS Google Map SDK 崩溃