javascript - Loading a page from hash on refresh -
so wrote piece of javascript using jquery library. functionality have pages load inside of div instead of entire page (to make modifying layout way easier).
i've made saves 'file url' in hash , i've made loads correctly, can't life of me figure out how go page.
when try go page hash in name (so example refreshing page, or going through link/url) replicates (i think) 2 times inside each other. can see happening live @ overeten.be , try refresh random page except main one.
could me problem? in advance!
$("document").ready(function(){ $('._body').load("pages/default.html"); var locationhash = window.location.hash.replace('#',''); if ((locationhash=='pages/default.html')||(locationhash=='')){ console.log("no page, "+locationhash); } else{ $('._body').load(window.location.hash); console.log(locationhash); } $('.menubundle a, footer a').on('click', function (e) { e.preventdefault(); var page = $(this).attr('href'); $('._body').fadeout(1000,function(){ document.location.hash = page; $('._body').load(page).fadein(1000); }); }); });
the problem on line:
$('._body').load(window.location.hash); if inspect window.location.hash, this:
window.location.hash "#pages/over_eten/feit.html" that url points current page. want this:
window.location.hash.slice(1) // skip first character "pages/over_eten/feit.html" on side note, seems weird me have 2 calls $('._body').load(). first 1 seems belongs right above console.log('no page...') instead.
Comments
Post a Comment