angularjs - Cordova url 和图像 src 在 Windows 中的 url 前面有 'unsafe'

标签 angularjs cordova windows-10

我正在使用 Angular 开发一个 Cordova 应用程序,我正在为 Windows 做一些努力。

我正在尝试这样的事情:

<img ng-src="{{dataDirectory + buildingPhoto.FilenamePhoto}}" class="full-width">

dataDirectory = "ms-appdata:///local"
buildingPhoto.FilenamePhoto = "VOL-00122kaftfoto_thumb.png"

但这只会导致使用此代码的图像损坏:

<img class="full-width" src="unsafe:ms-appdata:///local/VOL-00122kaftfoto_thumb.png" ng-src="ms-appdata:///local/VOL-00122kaftfoto_thumb.png">

我认为 unsafe 意味着前缀被视为不安全,需要将其列入白名单,因此我在 app.js 中添加了这个:

.config(['$compileProvider', function($compileProvider) {

    $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|file|ghttps?|ms-appx|ms-appdata|x-wmapp0):/);
    $compileProvider.imgSrcSanitizationWhitelist(/^\s*(https?|ftp|file|ms-appx|ms-appdata|x-wmapp0):|data:image\//);
}])

我还在 index.html 中添加了这个元标记:

<meta http-equiv="Content-Security-Policy" content="ms-appdata *; default-src *; img-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'" />

但它不起作用,所以我有点卡在这里,希望有人能把我推向正确的方向。

最佳答案

使用以下代码将图像 src 白名单修复:

$compileProvider.imgSrcSanitizationWhitelist(/^\s*(https?|ftp|file|content|blob‌​|ms-appx|ms-appdata|x-wmapp0|unsafe|local):|data:image\//);

还要确保 $compileProvider 在 app.js 中的初始设置之后不会被其他任何地方覆盖,这实际上导致了 Joris 的问题。

关于angularjs - Cordova url 和图像 src 在 Windows 中的 url 前面有 'unsafe',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37748205/

相关文章:

javascript - 元素及其父元素指定了 ng-click,两者都被称为

android - Wowza Media Server IOS 设备的实时视频流延迟?

javascript - 从 sqlite 数据库加载数据并打印到 html 元素

c++ - 管道在 Windows 7 上的 WinApi 中不起作用,但在 Windows 10 上起作用

使用 UTF-8 编码的 Powershell 字符串变量

c++ - 如何确定 Windows 10 中是否打开了高对比度主题?

angularjs - 如果 url 不包含特定路径,则应用重写规则

javascript - 替换电子邮件模板中的占位符

javascript - 在 angularjs 中的行和列中创建动态复选框按钮

ios - Ionic ios 模拟器不加载谷歌地图