views:

77

answers:

3

Hello,

I'm working on a small site that I would like to change a little bit so it is more dynamic. The index .html is something like

<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
...
</head>
<body>
    <div id="page">
        <div id="header"></div>
        <div id="main">
            <div id="menu"></div>
            <div id="content"></div>
        </div>
        <div id="footer"></div>
    </div>
</body>
<html>

I use jQuery and for example I load a "menu.html" file in the "menu" div. Menu.html is something like:

<ul>
    <li><a id="item1">item 1</a></li>
    <li><a id="item2">item 2</a></li>
</ul>

With JQuery I have added some code so that when clicking on the "item1" link then a item1.html file is loaded in the "content" div. This works fine except that I do not get any accents from menu1.html (I have some '?' instead).

The item1.html is something like:

Hello, this is my file
c'est un <strong>fichier</strong> avec des accents à, é

I do not have any html, body tags in those files (there are only there in the index.html).

Could you please help ?

Thanks a lot,

Luc

+2  A: 

You'll need to encode the accented characters. I would try HTML entites first:

é = &eacute;
à = &agrave;

If that doesn't work, you can use unicode encoding:

é = \u00e9
à = \u00e0
Pat
oh... so I will not be able to contribute in my item1.html file without having to encode the chars ? :-( There are no other options ? I was thinking of adding a html tag to indicate the encoding, this cannot be done ?
Luc
Unfortunately not that I know of. Once you load item1.html, you could use jQuery to find/replace accented chars with their entities.
Pat
A: 

if using Internet Explorer, did you try View / Encoding and checking 'Autoselect'.

do you get the same issue with other browsers?

Walid
I have this issue with firefox. I did not tried some other browser yet.
Luc
+1  A: 

This looks like encoding problems.

Is your item1.html encoded by iso-8859-1? Is your web server configured to include iso-8859-1 into headers of a web page? Do accents work in your main file if placed there? Try to check that encodings in every file are the same and sent correctly.

If that doesn't work you can also try switching the whole project to utf-8. There is almost no reason for using iso these days especially in non-english projects.

Pat's answer will probably work for you quickly, but will not solve the underlying issue and will complicate the creation of new pages.

kojo
Hello, in fact there are no encoding in item1.html. It is just heml code as described above without any <html>, <head>, <body> tags. Ok, I will try with utf-8 (setting this ONLY in the index.html file should do the trick ?). You'r right, I do not want the page creation to be more complicate.
Luc
Every text file has an encoding. Usually text editors can detect those for you and display your text files (or htmls) properly. This is not the case for web browsers. Thus, `item1.html` has encoding too. If you are using notepad.exe that comes with windows, you can see the encoding box in "Save As..." dialog. Any other text editors support saving in various encodings as well. Refer to their manual for details.
kojo
Also, you can read about character encoding in wikipedia: http://en.wikipedia.org/wiki/Character_encoding
kojo
ok, got it, so in my case the encoding comes from vi :-)
Luc
Adding this in my .vimrc file and editing each file solved my pb :)filetype on autocmd FileType html set fileencoding=utf-8
Luc