Incluso si sus anclajes tienen nombres de etiquetas únicos, cuando navega a través del historial del navegador y vuelve a ese ancla en particular, no ejecutará el JavaScript asociado con el cierre de ese ancla.
Debe configurar Window.onhashchange para llamar a su función de programa. Ni siquiera necesitas OnClick después del cambio. He probado lo siguiente:
<pre>
<html>
<head>
<script type="text/javascript">
window.onhashchange=window.onload=function(){
window.setTimeout(doHashCheck, 10);
}
var doHashCheck = (function(global) {
return function() {
var addr = window.location.hash.replace(/^#/,'');
show(addr);
}
})(this);
function show(addr)
{
a=new XMLHttpRequest();
a.onreadystatechange=function()
{
if (a.readyState==4 && a.status==200)
{
document.getElementById("content").innerHTML=a.responseText;
}
}
a.open("GET",addr+".php",true);
a.send(); //
}
</script>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache" />
<META HTTP-EQUIV="Expires" CONTENT="-1" />
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, no-store, must-revalidate" />
</head>
<a href="#1">Load 1.php into content</a>
<a href="#2">Load 2.php into content</a>
<a href="#3">Load 3.php into content</a>
<a href="#4">Load 4.php into content</a>
<!-- Load content here-->
<div id="content"></div>
</body>
</html>
</pre>