When a page is loaded, I want it to automatically scroll to the #content
section without changing the URL.
I attempted to achieve this using the following code:
window.location.hash = "content";
window.location.replace("#content", "");
However, the #content
still appears in the URL.
Is there a more effective approach to accomplish this?
Update:
I also tested out the following code:
window.location.hash = "content";
window.location.replace(window.location.toString().replace("#content", ""));
Unfortunately, this created a loop in the browser.