javascript - Getting history.js to fire a function -
i want history.js work on homepage: http://www.dinomuhic.com/2010/index.php
the main javascript code of homepage here: http://www.dinomuhic.com/2010/js/bunch.js
my homepage self-coded, no cms, wordpress or whatever. whole site works this: whatever click on has id, id being send sndreq function , content appears.
when click example on "motion" link being send
javascript:sndreq('k001','main-menue','menue-open','motion')
it's 4 vars. first id, 3 vars google analytics correct tracking.
now did linked history.js script index page can see , added line sndreq function:
history.pushstate( {state:1}, "dinomuhic.com - "+label, "?="+req );
i did nothing more. means did not add other lines of code history.js work.
so works appends correct string url. clicking on motion button results in url string looking this:
http://www.dinomuhic.com/2010/index.php?=k001
which good, because bookmarkable , sending id works , displays right content.
and when push button replaces string 1 before. not fire sndreq function again content of last click appears on screen. url string changes not content.
i need make history.js save sndreq function calls , call them again when pressing or forward buttons again.
i hope explained sufficently.
if make simpler assume i'm sending id , not other 3 vars google analytics, because work when sending id , not rest.
thanks in advance
ok think figured out.
basically need this:
history.adapter.bind(window,'statechange',function(){ var state = history.getstate(); sndreq(state.data[0],state.data[1],state.data[2],state.data[3]); });
this how call function every time press on button. has inside $(function (){}
function, active time.
but sndreq function data needs display correct content added line sndreq function
var snddata= new array(req,category,action,label);
this array filled inputs sndreq gets when click on link.
then give data on push state command
history.pushstate( snddata, "dinomuhic.com - "+label, "?="+req);
and works ;) made page test out, it's not yet in live version.
test site: http://www.dinomuhic.com/2010/index0.php
Comments
Post a Comment