1

I have a javascript file linked externally. And inside that javascript, I have this function:

function getMonthNumber(monthName){
monthName = monthName.toLowerCase();
if(monthName == 'janvier'){
    return "01";
}else if(monthName == 'février'){
    return "02";
}else if(monthName == 'mars'){
    return "03";
}else if(monthName == 'avril'){
    return "04";
}else if(monthName == 'mai'){
    return "05";
}else if(monthName == 'juin'){
    return "06";
}else if(monthName == 'juillet'){
    return "07";
}else if(monthName == 'août'){
    return "08";
}else if(monthName == 'septembre'){
    return "09";
}else if(monthName == 'octobre'){
    return "10";
}else if(monthName == 'novembre'){
    return "11";
}else if(monthName == 'décembre'){
    return "12";
}

}

But, when I read it in Firebug, I see:

function getMonthNumber(monthName){
    monthName = monthName.toLowerCase();
    if(monthName == 'janvier'){
        return "01";
    }else if(monthName == 'février'){
        return "02";
    }else if(monthName == 'mars'){
        return "03";
    }else if(monthName == 'avril'){
        return "04";
    }else if(monthName == 'mai'){
        return "05";
    }else if(monthName == 'juin'){
        return "06";
    }else if(monthName == 'juillet'){
        return "07";
    }else if(monthName == 'août'){
        return "08";
    }else if(monthName == 'septembre'){
        return "09";
    }else if(monthName == 'octobre'){
        return "10";
    }else if(monthName == 'novembre'){
        return "11";
    }else if(monthName == 'décembre'){
        return "12";
}
} 

So that, basically all the accents were encoded.

As far as I found on the net, passing the charset to the script should fix that, but even though I tried passing charset="utf8" or charset="ISO-8859-1", none seems to work.

I'm not sure how to fix that. Any ideas?

4
  • You should also save your file as UTF-8, if you haven't already Commented Mar 2, 2012 at 21:34
  • First, figure out the actual character encoding of that file... Commented Mar 2, 2012 at 21:35
  • Yes, I do own the file. How can I find the character encoding of a file? Commented Mar 5, 2012 at 15:45
  • Ah! Got it! Basically, dreamweaver was saving the file in a the wrong charset. So I opened the file in Eclipse and saved it and now it works (and it works if I remove the charset on the script) Thanks, JKirchartz and Šime Vidas for leading me on the right path. Commented Mar 5, 2012 at 15:53

4 Answers 4

1

Make the server specify, in HTTP headers, the encoding with charset=utf-8 (with the hyphen in the value; utf8 is not correct). If problems remain, post a URL; it is possible that for some reason, the HTTP header is not sent as intended.

Sign up to request clarification or add additional context in comments.

Comments

1

As stated by JKirchartz and Šime Vidas, the answer was to make sure to save the file in the right charset. Basically, dreamweaver was not saving it the good charset, but Eclipse does. So I removed the charset attribute on the script and just saved it in the good charset and now it works.

Comments

1

You can change your Dreamweaver preference to save files in Unicode. This will allow your special characters to appear correctly in a UTF-8 encoded document.

See Set Fonts preferences for documents in Dreamweaver.

Comments

0

To expand on Jukka's answer, make sure that if your doctype is HTML 5, set your meta charset like so:

<head>
  <meta charset="utf-8">
</head>

2 Comments

Why is this HTML5? It looks like pretty much the same thing we had before?
@GGG: apparently it's not only HTML5. Believe it or not, I'm only familiar with HTML5 and use it exclusively. I figured it may be the same as before, but I didn't know for sure.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.