Join the Stack Overflow Community
Stack Overflow is a community of 6.3 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

Hello,

I'm working on a response system.

((1) works) So basically when someone inputs, let's say "Coleus bluei" on the input field, the data goes to a database, a checks what's the output for that, in that case is pure HTML containing the plant information, and it works perfectly...

((2) fails) Now, in other cases, lets say, when the input "facebook", the output in the database is is Javascript code, which is supposed to redirect the user directly to facebook, and in that case, angular includes the Javascript code without any problem, but it won't wont.

I'm binding the data like this:

<div ng-bind-html="eirana_knows.posicion_superior | unsafe">

and here's the application filter "unsafe":

app.filter('unsafe', function($sce) { return $sce.trustAsHtml; });

I've seen as well, that for some reason, angular will execute Javascript code embed inside an HTML structure, such as:

<a onmouseover="alert('This works fine')" href="">works</a>

But in the other hand:

<script type="text/javascript">alert('This will not work');</script>

I'm using Angular 1.5.7 and Angular Sanitize 1.4.8, from the CDN

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-sanitize.js"></script>

Module properly loaded into the Angular app:

var app = angular.module('resonador', ['ngSanitize']);
share|improve this question
    
This looks like a duplicate: stackoverflow.com/questions/20297638/… – Todd Miller Aug 15 at 21:08
    
Yes sir! seems like it might work! 1,000 Thanks! – Chris Russo Aug 16 at 10:56
    
No sir... can't make it work with plain Javascript. – Chris Russo Aug 16 at 11:53
    
It might not work at all. It's pretty dangerous to allow dynamically inserted JavaScript to execute on a page. – Todd Miller Aug 16 at 12:47
    
Well, the content is actually on the database, so, if they can insert the content on the database on first place... – Chris Russo Aug 16 at 12:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.