0

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']);
7
  • This looks like a duplicate: stackoverflow.com/questions/20297638/… Commented Aug 15, 2016 at 21:08
  • Yes sir! seems like it might work! 1,000 Thanks! Commented Aug 16, 2016 at 10:56
  • No sir... can't make it work with plain Javascript. Commented Aug 16, 2016 at 11:53
  • It might not work at all. It's pretty dangerous to allow dynamically inserted JavaScript to execute on a page. Commented Aug 16, 2016 at 12:47
  • Well, the content is actually on the database, so, if they can insert the content on the database on first place... Commented Aug 16, 2016 at 12:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.