I have a single page site made with <div>
tags moving, hiding, ect.. I need to be able to have the back button control the functions running my divs.
I have been doing my research no how to do this and came across this article.
I have included this code in my site and it works great for updating the URL with incrementing hashtag numbers every time the user clicks a button with the doclick() function attached.
var times = 0;
function doclick() {
times++;
location.hash = times;
}
window.onhashchange = function() {
if (location.hash.length > 0) {
times = parseInt(location.hash.replace('#',''),10);
} else {
times = 0;
}
document.getElementById('message').innerHTML =
'Recorded <b>' + times + '</b> clicks';
}
I have 4 buttons on my site calling doclick()
<div onClick="edit(); doclick()">Editorial</div>
<div onClick="vfx(); doclick()">VFX</div>
<div onClick="audio(); doclick()">Audio</div>
<div onClick="color(); doclick()">Color</div>
I am not experienced enough to see how to do what I need though.
Now that I am storing every click in a new hash, how can I use that data to call specific functions I already have setup? Or maybe there is a better way to tweak so that instead of just adding #1, #2 etc.. URL will reflect page name. Like www.site.com/vfx - And I could use that information to call a function.
Example Usage:
- We start on home page www.site.com
- User clicks EDITORIAL BTN - divs switch out, on on Editorial, URL reads www.site.com/editorial
- User clicks VFX BTN - divs switch out, now on VFX page. URL reads www.site.com/vfx
- User clicks back button - now calls same function edit() and goes back to www.site.com/editorial