Saturday, May 11, 2024
 Popular · Latest · Hot · Upcoming
114
rated 0 times [  120] [ 6]  / answers: 1 / hits: 30461  / 15 Years ago, mon, october 19, 2009, 12:00:00

I am trying to reload current page with different url hash, but it doesn't work as expected.



(Clarification how I want it to work: Reload the page and then scroll to the new hash.)



Approach #1:



window.location.hash = # + newhash;


Only scrolls to this anchor without reloading the page.



Approach #2:



window.location.hash = # + newhash;
window.location.reload(true);


Kinda works but it first scrolls to the anchor, then reloads the page, then scrolls to the anchor again.



Approach #3:



window.location.href = window.location.pathname + window.location.search + &random= + Math.round(Math.random()*100000) + # + newhash;


Works but I would rather not add random garbage to the url.



Is there a better solution?


More From » url

 Answers
0

Remove the anchor you're going to navigate to, then use approach #2? Since there's no anchor, setting the hash shouldn't scroll the page.


[#98486] Wednesday, October 14, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
blair

Total Points: 384
Total Questions: 108
Total Answers: 86

Location: Northern Ireland
Member since Tue, May 5, 2020
4 Years ago
;