ionic2 url不安全问题 caused by: unsafe value used in a resource URL context
来源:互联网 发布:初学者买口琴知乎 编辑:程序博客网 时间:2024/05/16 05:52
ionic2 中,img,iframe的src,a的href,有需要引入外部url的资源链接,但是,变量直接赋值url的话,会报错:
caused by: unsafe value used in a resource URL context (see http://g.co/ng/security#xss)
顾名思义,加上看了官网文档:
http://http://g.co/ng/security#xss
明白了,是ionic2做了安全限制!
对应的html文件中是这样:
<iframe class="all-iframe" [src]="srcUrl"></iframe>
解决方法:
1.在对应ts文件中,导入DomSanitizer
import {DomSanitizer} from '@angular/platform-browser';
2.引用DomSanitizer
export class WebPage { srcUrl:any; constructor(private sanitizer: DomSanitizer) { this.srcUrl = this.sanitizer.bypassSecurityTrustResourceUrl(navParams.get('url')); }
注意:srcUrl类型为any,不能是string了
1 0
- ionic2 url不安全问题 caused by: unsafe value used in a resource URL context
- ionic2 url不安全问题 caused by: unsafe value used in a resource URL context
- Ionic2中嵌入图片,音频url地址,出现“WARNING: sanitizing unsafe URL value”错误的解决方法
- Path used in ActionScript-Url,Absolute Url,Relative Url
- Tomcat8.0部署web发生Caused by: java.lang.IllegalArgumentException: Invalid <url-pattern> /*.do in servle
- struts Caused by: no protocol dtd - Class: java.net.URL
- OAuth2 401 Bad Credentials Caused By Incorrect URL
- An issue caused by Initial Value in boost sparse matrix
- angular-resource的url转义问题
- Sort a dictionary by value in JavaScript
- 关于url中特殊字符的问题(url不安全字符和保留字符)
- Getting the Requesting URL in a Servlet
- Resource IDs cannot be used in a switch statement in Android library modules
- redis-2.8.9 cannot get a resource from the pool caused by 连接拒绝
- Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or pat
- Could not resolve placeholder 'master.jdbc.url' in string value "${master.jdbc.url}"
- Could not resolve placeholder 'jdbc.url' in string value "${jdbc.url}"
- Could not resolve placeholder 'jdbc.url' in string value "${jdbc.url}"
- 设计模式六大原则(4):接口隔离原则
- 备忘录模式
- 关于Android Studio时出现cannot resolve symbol R报错的解决方法
- python模拟银行家算法
- 诸葛亮给子书
- ionic2 url不安全问题 caused by: unsafe value used in a resource URL context
- 树回归的实现
- 详细hbase
- Android Near Field Communication
- java中的关键字
- git之本地仓库关联远程仓库
- js中arguments,callee,caller的用法小结
- ionic添加cordova插件-Dialogs
- javascript 字符转义方法