I am using code from this tutorial
In the URL, it is weird; If I were to click on home, it'll go to example.tld/home#, but I would like to have the hash on the back. example.tld/#home. If I were to go to the contact page, it'll display as /home#co … doesn't display the whole word. (contact). I would like #contact to replace #home when I change the page. Also how can I land on a different page on load instead of #home again? Example: click on example.tld/#contact, goes to #contact page.
Also...Here is the code I have modified from the tutorial:
// Check for hash value in URL
var hash = window.location.hash.substr(1);
var href = $('nav ul li a').each(function(){
var href = $(this).attr('href');
if(hash==href.substr(0,href.length-5)){
var toLoad = hash+'.html #main-content';
$('#content').load(toLoad)
}
});
$('nav ul li a').click(function(){
var toLoad = $(this).attr('href')+' #main-content';
$('#main-content').hide('fast',loadContent);
$('#load').remove();
$('#wrapper').append('LOADING...');
$('#load').fadeIn('normal');
window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-5);
function loadContent() {
$('#main-content').load(toLoad,'',showNewContent())
}
function showNewContent() {
$('#main-content').show('normal',hideLoader());
}
function hideLoader() {
$('#load').fadeOut('normal');
}
return false;
});
Think I should cach some of the selectors that are being repeated?
Also here is the HTML:
… content to be loaded
Nav:
I'm using htaccess so I do not have to include the file extension, but if its needed, the files are .php
Let's say i'm on #home and if I click the #home link again, it'll reload the same page, is there any way to stop this if i'm already on that page?