i have a music site where i used ajax with server side php to load pages dynamically to prevent reload. this function works with different directories that are contains pages and also uses hash to show pages urls but i have one issue and that is my back and forward buttons on browser didn't browse through pages and its really awkward! i heard about html history api and also a plugin on that history.js but unfortunately couldn't figure out how these will work. please don't guide me to guides ans manuals because i already tried all those with no success, below is the code code that is currently i am using if anybody can modified it so it starting working with back and forward buttons support either using HTML5 history api or history.js which is again a history api plugin. any help will be really appreciated. this is my navigation menu.
<nav> <ul id='menu' class="menu-items"> <li><a href="#Browse_Page0" class="active"><i class="arcd-archive"> </i></br>Browse</a></li> <li><a href="#Top_albums_Page0"><i class="arcd-music97"></i></br>Top albums</a></li> <li><a href="#Top_artists_Page0" ><i class="arcd-microphone52"></i></br>Top artists</a></li> <li><a href="#Top_lists_Page0" ><i class="arcd-numbered8"></i></br>Top lists</a></li> <li><a href="#Charts_Page0" ><i class="arcd-rising9"></i></br>Charts</a></li> </ul> </nav>
and this is ajax jquery function
$(function () {
$('nav ul#menu a').on('click', function () {
var linkClicked = $(this).attr('href');
var data = {
page : linkClicked.replace(/\D/g, ''),
directory : linkClicked.replace(/(_Page(.*)|#)/g,'')
}
$("nav ul#menu a").removeClass("active");
$(this).addClass("active");
$('#loading').css('visibility', 'visible');
$.post('load.php', data, function(msg) {
$('#Home_page-content').html(msg);
$('#loading').css('visibility', 'hidden');
$('#Home_page-content section').hide().fadeIn(1000);
}, '');
});
});
and load.php on server side that used by above function.
<?php
$page = filter_var( $_POST['page'], FILTER_VALIDATE_INT);
$dir = filter_var( $_POST['directory'], FILTER_SANITIZE_STRING);
if ( $page !== false && $dir !== false ) {
$link = $dir . '/' . $dir . '_Page' . $page . '.php';
if ( file_exists( $link ) ) {
echo file_get_contents( $link );
} else {
echo 'There is no such page!';
}
}
?>
i will very much appreciate any kind of help. thanks