I have a similar question to this post.
But adding "javascript" what was proposed in the answer didn't resolve my problem:
$compileProvider.urlSanitizationWhitelist(/^\s*(https?|ftp|mailto|file|javascript):/);
My code looks something like:
<a ng-href="{{var1 ? '/home' : 'javascript: void(0);'}}" ng-bind="var2"></a>
But in the url, it produces an unsafe:javascript: void(0);
Using javascript: , you can run code that does not change the current page. This, used with void(0) means, do nothing - don't reload, don't navigate, do not run any code. The "Link" word is treated as a link by the browser. For example, it's focusable, but it doesn't navigate to a new page.
JavaScript void 0 means returning undefined (void) as a primitive value. You might come across the term “JavaScript:void(0)” while going through HTML documents. It is used to prevent any side effects caused while inserting an expression in a web page.
I assume you use the latest version of AngularJS. The method name has been changed since that SO answer.
myapp.config(function($compileProvider){
$compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|file|javascript):/);
});
Demo link.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With