Value coding format (input)

Asked

Viewed 207 times

0

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

Trying that:

 <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>
  • 1

    because it doesn’t use UTF-8 instead of ISO-8859-1 ??

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: Make sure the text editor is as ANSI compatible with ISO-8859-1.

  • Very good is what I needed.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.