Stop default hashtag behavior with jquery

后端 未结 3 527
孤独总比滥情好
孤独总比滥情好 2020-12-16 04:20

I\'m using the following code to append a hashtag to the end of a url. That way someone can copy that url and take them back to that page, with certain divs visable.

3条回答
  •  囚心锁ツ
    2020-12-16 04:49

    It depends. If you want to prevent it when the anchor is clicked, use this:

    $("a.live").click(function(e) {
        e.preventDefault(); // Prevents browsers default action
        window.location.hash = 'live'; 
        $("#live").slideDown();
    });
    

    If you want to prevent it from scrolling to the hash when the page is loaded, I'm not sure how you would prevent that.

提交回复
热议问题