1

I am using this solution here to remove script elements from ajax responses. However, when my response looks like this :

'console.log("test");https://x.ya.com/home?abc=1&currency=EUR'

It converts the &curren to ¤ symbol.

The result looks like this: 'https://x.ya.com/home?abc=1¤cy=EUR'

How do I avoid this?

Community
  • 1
  • 1
mojorisinify
  • 377
  • 5
  • 22
  • There are a lot of poor answers on that question. Which one are you using specifically? Post code. – Chet Dec 11 '15 at 18:27
  • I am using the top answer to the question : Here is the code function stripScripts(s) { var div = document.createElement('div'); div.innerHTML = s; var scripts = div.getElementsByTagName('script'); var i = scripts.length; while (i--) { scripts[i].parentNode.removeChild(scripts[i]); } return div.innerHTML; } – mojorisinify Dec 11 '15 at 19:22

2 Answers2

1

Try using the escaped ampersand & to represent the character & in the HTML where this problem occurs, like so;

HTML

<a href="http://example.com/home?abc=1&amp;currency=EUR">Example Link</a>

Produces

Example Link

Benjy1996
  • 159
  • 7
  • i dont have control over the url.. this was just an example.. there could be multiple others. – mojorisinify Dec 11 '15 at 19:21
  • I'm a bit unsure as to what you are doing, can you not replace the string "&currency" with "&currency" at any stage with what you're doing? Even in a small script in JavaScript? – Benjy1996 Dec 11 '15 at 19:42
  • its not just about &curren, there are a hundred other cases. Replace is just not going to work. – mojorisinify Dec 11 '15 at 19:56
1

I used the approach as mentioned in the answer here. This removes all the script elements from the text without treating it as html (without creating a div and appending the text to innerHTML of the div), which solves the case.

No html = no html symbol decode.

Works for me!

Community
  • 1
  • 1
mojorisinify
  • 377
  • 5
  • 22