utf 8 - Javascript: how to convert text copied into textarea from any encoding to UTF-8? -
i have simple html+js page <textarea>
.
user supposed paste text inside it, , page use pasted text parameter remote service url expects utf-8.
my current code this:
<body> <textarea id="editor"></textarea> </body> <script> var content = document.getelementbyid('editor').innerhtml; content = striptags(content); content = decodehtml(content); content = encodeuricomponent(content); var url = remoteservicebaseurl + content; window.open(url, '_blank'); function striptags(input) { return input.replace(/<(.|\n)*?>/g, ''); } function decodehtml(html) { var txt = document.createelement("textarea"); txt.innerhtml = html; return txt.value; } <script>
but has trouble - example - %0c
(form-feed
) character found in windows-1252
texts: when calling url thrown error urierror: malformed uri sequence
.
so question is: how convert text utf-8, indipendently source encoding, javascript?
Comments
Post a Comment