views:

45

answers:

1

On loading a page I would like it to go to #content without changing the url.

I thought I would be able to use

window.location.hash = "content";
window.location.replace("#content", "");

but #content still exists on the url.

Any better method?


Edit:

Also tried

window.location.hash = "content";
window.location.replace(window.location.toString().replace("#content", ""));

But this sends the browser into a loop.

+1  A: 

You could find the vertical position of the anchor with that id, and then scroll to that position.

Andrew Cooper
So easy. Thanks!
David John Smith