gpt4 book ai didi

angularjs 不安全的 ng-href 使用 javascript : void(0);

转载 作者:行者123 更新时间:2023-12-03 14:33:09 24 4
gpt4 key购买 nike

关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。












想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。

5年前关闭。




Improve this question




我对 this post 有类似的问题.

但是在答案中添加“javascript”并没有解决我的问题:

$compileProvider.urlSanitizationWhitelist(/^\s*(https?|ftp|mailto|file|javascript):/);

我的代码看起来像:
<a ng-href="{{var1 ? '/home' : 'javascript: void(0);'}}" ng-bind="var2"></a>

但是在 url 中,它会产生一个 unsafe:javascript: void(0);

最佳答案

我假设您使用的是最新版本的 AngularJS。自该 SO 答案以来,方法名称已更改。

myapp.config(function($compileProvider){
$compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|file|javascript):/);
});

Demo link .

关于angularjs 不安全的 ng-href 使用 javascript : void(0);,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19127749/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com