jQuery - Reload page after following jump link
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";
精彩评论