Bonjour � tous,

actuellement en train de travailler sur un projet web en entreprise, je rencontre quelques difficult�s en javascript sur le navigateur IE 7 sur lequel doit fonctionner mon application.

Afin de vous faire partager mon probl�me, j'ai �crit une petite page :

Code : S�lectionner tout - Visualiser dans une fen�tre � part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<html>
    <head>
        <title>IE Anchor Test</title>
        <script type="text/javascript">
        function test()
        {
            window.setInterval(function ()
                {
                    document.getElementById('window.location.hash').innerHTML = window.location.hash;
                    document.getElementById('window.location.href').innerHTML = window.location.href;
                    document.getElementById('self.location.href').innerHTML = self.location.href;
                    document.getElementById('top.location.hash').innerHTML = top.location.hash;
                    document.getElementById('window.parent.location.hash').innerHTML = window.parent.location.hash;
                }, 100);
        }
        </script>
    </head>
    <body onload="test()">
        <table border="1">
            <tr>
                <td>window.location.hash</td>
                <td id="window.location.hash"></td>
            </tr>
            <tr>
                <td>window.location.href</td>
                <td id="window.location.href"></td>
            </tr>
            <tr>
                <td>self.location.href</td>
                <td id="self.location.href"></td>
            </tr>
            <tr>
                <td>top.location.hash</td>
                <td id="top.location.hash"></td>
            </tr>
            <tr>
                <td>window.parent.location.hash</td>
                <td id="window.parent.location.hash"></td>
            </tr>
        </table>
        <br /><hr /><br />
        <a href="#test1">test1</a><br />
        <a href="#test2">test2</a><br />
        <div id="test1"></div>
        <div id="test2"></div>
    </body>
</html>
On a donc, 2 div vides en bas de page avec les id "test1 et test2"
2 liens d'ancre menant vers les div en question, un tableau qui affichera des informations, aliment� par ma fonction js "test" lanc�e via un onload.

Comme vous pouvez le voir, toutes les 100 millisecondes des informations JS sont affich�es dans le tableau. Ces informations sont :

window.location.hash
window.location.href
self.location.href
top.location.hash

La d�marche � suivre :

- Cliquez sur le lien test1 => l'ancre change dans la barre d'adresse, les infos dans le tableau sont correctes
- Cliquez sur le lien test2 => l'ancre change dans la barre d'adresse, les infos dans le tableau sont correctes
- Appuyez sur le bouton retour du navigateur => l'ancre change dans la barre d'adresse, les infos dans le tableau sont incorrectes!

En effet, je m'attends � retrouver "#test1" dans window.location.hash, et bien non je garde "#test2". Sous firefox 3.6.8 / 3.6.9 pas de soucis.

Malheureusement, les 3000 employ�s de la boite sont sous IE 7 et pas question de changer, je cherche donc une solution � mon probl�me.

Initialement, le but de cette manipulation �tait de d�tecter un changement au niveau de l'ancre, sur IE 8 ou firefox (version ?) un �v�nement onhashchange existe. Sous IE 7, je pensais pouvoir surveiller la valeur de window.location.hash, mais apparemment cette propri�t� n'est pas mise � jour correctement.

Apr�s avoir cherch� des solutions alternatives 2 jours, je finis par me retourner vers vous.

Que pensez vous de ce probl�me? Est-ce pour vous un bug au niveau d'IE 7?
Voyez vous une solution possible pour d�tecter un changement d'ancre dans le cas de la navigation dans l'historique d'IE 7?

Merci.