As you will see on the code below, the unicode decoder works on alert but when it comes to textarea listener, it doesn’t work as expected, could you catch the problem?
<textarea name="" id="first" cols="75" rows="15"></textarea>
<textarea name="" id="result" cols="75" rows="15"></textarea>
const jsEscape = (str) => {
return str.replace(new RegExp("'", 'g'),"\'");
}
const decodeUnicodeEntities = (data) => {
return unescape(jsEscape(data));
}
alert(decodeUnicodeEntities('http://x.comu0026shop_id=123'), 'check')
$('#first').on('change keyup paste', function() {
$('#result').val(decodeUnicodeEntities($(this).val()));
});
Also live pen, https://codepen.io/RainThemes/pen/yLqgdXK
Solved with this, https://stackoverflow.com/a/23937764/10413531
2
Answers
Try this code :
This will ensure that the value of #result is updated whenever the value of #first changes.
here are all escape sequences defined: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#escape_sequences
they’re not that many and fairly straightforward to parse