Charset does not work in JavaScript

1

I have the following JavaScript function that issues a confirm with a message that contains special characters.

function cancelaCadastro(){
    var cancelaCadastro = confirm(unescape("Você deseja cancelar o cadastro e voltar à página inicial?"));
    if (cancelaCadastro == true){
        location.href= "index.php";
    } else{
        return false;
    }
}

The problem is that the message is being displayed as follows. "Do you want to cancel the registration and return to the homepage?".

I put unescape to try to fix this error, but it was not effective. I would like to inform you that in the HTML page I already set charset to utf-8 and ISO , but it also did not solve the problem. Here is an example of meta-charset :

<meta http-equiv="Content-Type" content="text/html"; charset="UTF-8">

NOTE: This question is not a duplicate of the question Doubt with charset = iso-8859-1 and utf8 , because the problem is not related to using 2 different charset types. Anyway, I set the charset of the page by php using the line of code <?php header('Content-Type: text/html; charset=UTF-8'); ?>  and also saved the page as HTML without BOM, but the problem was not solved.

    
asked by anonymous 20.06.2017 / 15:45

2 answers

1

Add this code in the header of the PHP index file;

<?php header("Content-Type: text/html; charset=ISO-8859-1",true) ?>

I'm looking for results.

    
24.06.2017 / 00:45
1

Add the charset attribute in the script declaration. Example:

<script charset="UTF-8"></script>
    
20.06.2017 / 15:48