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?

2
  • There are a lot of poor answers on that question. Which one are you using specifically? Post code. Commented Dec 11, 2015 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; } Commented Dec 11, 2015 at 19:22

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

3 Comments

i dont have control over the url.. this was just an example.. there could be multiple others.
I'm a bit unsure as to what you are doing, can you not replace the string "&currency" with "&amp;currency" at any stage with what you're doing? Even in a small script in JavaScript?
its not just about &curren, there are a hundred other cases. Replace is just not going to work.
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!

1 Comment

Glad you got it sorted, sorry I couldn't help much

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.