我一直在处理示例 chrome 扩展中的链接问题。
Chrome 似乎认为我的内联代码(AngularJS 绑定(bind))不安全,这基本上意味着所有动态链接都不起作用。
例如,下面的链接(在 HTML 模板中,IndexCtrl):
<a href="#/edit/{{ i.id }}"> Edit </a>
呈现为以下内容,在 chrome 开发人员工具中查看时我得到了这个:
<a href="unsafe:chrome-extension://abcd/index.html#/edit/1"> Edit </a>
请注意,/edit/1 的 id
已通过 angular 正确绑定(bind) - 因此 chrome 很可能具有一些我将启用/禁用的安全功能,但如何启用/禁用?
有什么建议吗?仅供引用,控制台中没有错误。
最佳答案
确保您执行以下操作:
包括 CSP 声明:
<html lang="en" ng-app="app" ng-csp="">
使用
ng-href
<a ng-href="#/edit/{{ item.id }}">Link</a>
将chrome-extensions添加到Href Sanitization White list
var app = angular.module("app", []); app.config( function ($compileProvider) { $compileProvider.aHrefSanitizationWhitelist (/^\s*(https?|ftp|mailto|file|tel|chrome-extension):/); });
关于javascript - AngularJS - Google Chrome 扩展程序中的动态链接断开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20143358/