开发者

jQuery - Reload page after following jump link

开发者 https://www.devze.com 2022-12-25 00:08 出处:网络
I\'m creating a slideshow effect using hidden div\'s. Once a thumbnail is clicked, the corresponding div appears in a window and the other divs are hidden. However, I also need the page to reload. I a

I'm creating a slideshow effect using hidden div's. Once a thumbnail is clicked, the corresponding div appears in a window and the other divs are hidden. However, I also need the page to reload. I attempted to use something like this:

开发者_运维知识库
$("a").click(function() {
    location.reload();
});

However, this will reload the page without following the link (something like a href="#div02"). How do I get it to both follow the link and reload the page?


If I understand you correctly, what you want is to modify the URL of the browser to reflect the current state of the DOM. Meaning, if a user clicked on a picture, the URL would be updated by appending a "#div02" and finally the user would be able to share this link with friends which will take them directly to that picture/state.

If that's what you want, your looking for Location Hash. To set:

window.location.hash = "#div02";

To get:

window.location.hash


Rather than reload the page just remove the element that embeds the previous video.


You can add an extra parameter (with random value) to to your current url. The browser will reload the page and then jumb to an anchor since your url has changed.

var randomString = Date.now();
window.location = "?something=" + randomString + "#div02";
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号