Value (input) encoding format

0

Problem: I am passing the value of an input to a frame but the encoding format does not stay as it should - charset = ISO-8859-1

Trying this:

 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
 <script type="text/javascript">
 function update() {
 var html = document.getElementById('edit').value;
 var encodedHtml = unescape(encodeURIComponent(html));
 document.getElementById('carregar').src = 'data:text/javascript;charset=utf-8,' + encodedHtml;
 }
 window.onload = update;
 </script>
 <input type="hidden" id='edit' onkeyup='update();' onchange='update();' onload='update();' value='a&#231;&#227;o e reação'>
 <iframe id='carregar' style='width:100%;border:1px solid gray;height:50%;'></iframe>
    
asked by anonymous 26.02.2016 / 17:03

1 answer

1

Suggestion for correction:

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript">
function update() {
    var html = encodeURI(document.getElementById('edit').value);
    document.getElementById('carregar').src = 'data:text/javascript;charset=utf-8,' + html;
}
window.onload = update;
</script>
<input type="hidden" id='edit' onkeyup='update();' onchange='update();' onload='update();' value='ação e reação'>
<iframe id='carregar' style='width:100%;border:1px solid gray;height:50%;'></iframe>

Important : Ensure that the text editor is as ANSI compliant with ISO-8859-1 .

    
26.02.2016 / 18:11