0

I just tried this code and it works well to detect URL,

<script type="text/javascript"> $(document).ready(function () {
    if(window.location.href.indexOf("#2") > -1) {
       alert("your on slide 2");
    } }); </script>

But not for my case.

In fact, I want to put this in a slideshow which works like this : www.slideshow.com/#1, www.slideshow.com/#2... etc

So this code run if I refresh the slide 2, but not if I acces to this slide by clicking on the Next Slide Button on the first slide. I hope you understand my problem and help me find a solution

Thank you very much !

Clemeeent
  • 41
  • 1
  • 10

2 Answers2

3

window.location.hash and onhashchange event are what you are looking for.

http://stereointeractive.com/blog/2008/11/21/javascript-get-window-hashanchor-get-link-target/

JavaScript/jQuery - onhashchange event workaround

Community
  • 1
  • 1
Can Geliş
  • 1,454
  • 2
  • 10
  • 19
0

You probably want to use the pushState API

You can then listen to the popstate event to see when the user navigates.

And if you want to support browsers that don't support this, you'll probably need a pushState polyfill

Bjorn
  • 69,215
  • 39
  • 136
  • 164