0

I've got this html file

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <button type="button" onclick="changeText()">
            Change!
        </button>

        <p id='change'>Camión</p> <!-- It's OK-->


        <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
        <script src="jscaracteres.js" type="text/javascript" charset="UTF-8"></script>
    </body>
</html>

And this javascript function in "jscaracteres.js"

function changeText() {
    var newText = "Camión 2.0"; //Camión 2.0
    $("#change").html(newText); 
}

If I put the function inside html, there aren't any problem with special characters, but if I have the function changeText() in a .js file when I click the button, the text change to "Camión 2.0" instead of "Camión 2.0". I don't know where is the problem.

2 Answers2

0

It seems your js file encoding might be different than UTF-8, most Probably ISO-8859-1. But your html page encoding is UTF-8.

So Basically ó (in ISO-8859-1) changes to ó (in UTF-8).

You can try changing your js file encoding to UTF-8, that should work.

mmk
  • 480
  • 3
  • 10
  • But in the reference I've already set the encoding UTF-8 `` That's right or I have to set the encoding in other place?? – Anthonny Pazmiño Sep 20 '18 at 19:49
  • Are you using some IDE for development or just normal text editor. – mmk Sep 20 '18 at 19:55
  • Just to be sure you can probably create a new js file and save it with UTF-8 encoding and then try. Keep a backup of old file. If you are using windows, this can probably help to save file in particular encoding - https://stackoverflow.com/questions/3710374/get-encoding-of-a-file-in-windows – mmk Sep 20 '18 at 19:58
  • thank you, I had to open the file .js with nothepad and save with utf-8 encoding and it worked. But It's a bit rare... How can I configure netBeans to do that automatically? – Anthonny Pazmiño Sep 20 '18 at 20:20
  • see if this helps - https://stackoverflow.com/questions/4133195/how-to-change-file-encoding-in-netbeans – mmk Sep 21 '18 at 03:47
0

Finally I had to open the js file with notepad and save it with UTF-8 encoding.

Are there any way to configure NetBeans to do that automatically?