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 !

4

2 回答 2

3

window.location.hash 和 onhashchange 事件是您正在寻找的。

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

JavaScript/jQuery - onhashchange 事件解决方法

于 2013-01-26T14:56:42.210 回答
0

您可能想使用pushState API

然后,您可以收听popstate 事件以查看用户导航的时间。

如果你想支持不支持这个的浏览器,你可能需要一个 pushState polyfill

于 2013-01-26T14:54:09.133 回答