Detect URL change in Javascript - Stack Overflow

I just tried this code and it works well to detect URL,<script type="textjavascript">

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/#1, www.slideshow/#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 !

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./#1, www.slideshow./#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 !

Share Improve this question edited Jan 26, 2013 at 14:59 user2166576 asked Jan 26, 2013 at 14:51 ClemeeentClemeeent 511 silver badge11 bronze badges 1
  • you may finding pjax pjax.heroku. – farmer1992 Commented Jan 26, 2013 at 14:52
Add a ment  | 

2 Answers 2

Reset to default 3

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

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

JavaScript/jQuery - onhashchange event workaround

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745264500a4619371.html

相关推荐

  • Detect URL change in Javascript - Stack Overflow

    I just tried this code and it works well to detect URL,<script type="textjavascript">

    4小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信