Vous pouvez utiliser AJAX/PHP pour cela. Vous pouvez obtenir le hash avec javaScript et charger du contenu avec PHP. Supposons que nous charger le contenu principal d'une page, notre URL avec hachage est « http://www.example.com/#main »:
JavaScript dans notre tête:
function getContentByHashName(hash) { // "main"
// some very simplified AJAX (in this example with jQuery)
$.ajax({
url: '/ajax/get_content.php?content='+hash, // "main"
success: function(content){
$('div#container').html(content); // will put "Welcome to our Main Page" into the <div> with id="container"
}
});
}
var hash=parent.location.hash; // #main
hash=hash.substring(1,hash.length); // take out the #
getContentByHashName(hash);
Le PHP pourrait avoir quelque chose comme:
<?php
// very unsafe and silly code
$content_hash_name = $_GET['content'];
if($content_hash_name == 'main'):
echo "Welcome to our Main Page";
endif;
?>
duplication possible de [Peut PHP lire la partie hash de l'URL?] (Http://stackoverflow.com/questions/940905/can-php-read-the-hash-portion-of-the-url) –