jquery - Getting history.js to work without Ajax loaded pages -
i don't know why isn't working , i've been trying everything.
most of tutorials online using ajax i'm not , i've tried adapting can't work. i'm using has bang urls , content loaded in index page it's being shown , hidden dynamically. use getting history working.
here script...
history.adapter.bind(window, 'statechange', handlestatechange); $('nav a').on('click',function(e) { var target = $(this).attr('href'); history.pushstate(null, null, target); }); function handlestatechange() { alert("state changed..."); }
if alert happen can go there alert never fires , don't know why.
just define function before binding event, in way:
function handlestatechange() { alert("state changed..."); } history.adapter.bind(window, 'statechange', handlestatechange); $('nav a').on('click',function(e) { var target = $(this).attr('href'); history.pushstate(null, null, target); });
or better do, define function inside bind, of course if don't need use same function later in script.
history.adapter.bind(window, 'statechange', function() { alert("state changed..."); }); $('nav a').on('click',function(e) { var target = $(this).attr('href'); history.pushstate(null, null, target); });
Comments
Post a Comment