Reputation: 251
I want to refresh the page with an additional hash in the url. The problem is that the hash is added but the page is not reloaded which I want in this case. I have tried the following:
window.location.href = "http://www.mydomain.com/page1#test";
The hash is added in the url but the page is not reloaded. How do I achieve this functionality?
Upvotes: 1
Views: 119
Reputation: 15566
Depending on your requirement you can as well use onhashchange
event
window.onhashchange = function(){
if (location.hash === "#test") {
test();
}
}
Upvotes: 0
Reputation: 29176
Try -
location.reload(true);
after you've changed the url -
window.location.href = "http://www.mydomain.com/page1#test";
location.reload(true);
Check out this example from MDN.
Upvotes: 1