javascript - How to force a page to reload if all what was changed in url is hash? -


I am trying to reload the current page with current URL hash, but it does not work as expected .

(Explanation How do I want to do this: Reload the page and then scroll to the new hash.)

Approach # 1:

  Window.location.hash = "#" + NewHash;  

Approach # 2:

  window  

This anchor only scrolls without reloading the page Please.

.location.hash = "#" + NewHash; Window.location.reload (true);

Works a bit but it first scrolls the anchor, then reloads the page, then scroll over the anchor.

Approach # 3:

  window.location.href = window.location.pathname + window.location.search + "& amp; Random = "+ Math.round (Math.Rendum (* 100000) +" # "+ NewHash;  

Works but I will not add random garbage to URL.

Is there a better solution?

Remove anchor which you are about to navigate, then use Approach # 2? Because there is no anchor, setting hashes should not scroll the page.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -