0

I have a one page horizontal sliding website for mobile only. It gives an impression of a mobile app. So if I click a button (An tag) in one section, it slides to another by jQuery. All pages has buttons for navigation to different sections. And the url looks like this after slide - www.domain.com/#section. Everything works just fine.

Now I want to add browser's back/forward button event here as well. So, if I slide to section-2 and then click browser's back button I want to slide back to section-1. It means that somehow I have to detect browser's back/forward button click event and trigger my jQuery functions accordingly. Some basic idea would be very nice. Thanks.

Imrul.H
  • 5,760
  • 14
  • 55
  • 88
  • 1
    possible duplicate of [How to Detect Browser Back Button event - Cross Browser](http://stackoverflow.com/questions/25806608/how-to-detect-browser-back-button-event-cross-browser) – Markus Müller Feb 11 '15 at 14:48

1 Answers1

-3

Create a back button on a page:

<button onclick="goBack()">Go Back</button>

<script>
function goBack() {
    window.history.back()
}
</script>

Create a forward button on a page (This example will not work if the next page does not exist in the history list):

<button onclick="goForward()">Go Forward</button>

<script>
function goForward() {
    window.history.forward()
}
</script>
Carlos M. Meyer
  • 436
  • 3
  • 9