0
top.location.hash = "";

adds a # to my addressbar. As soon as top.location.hash = ""; is called and a # is added my browser window jumps to its top.

Is there any chance a could prevent that?

$('#element').live('click', function() {
        top.location.hash = "map";
    });
matt
  • 42,713
  • 103
  • 264
  • 397
  • In this case it may help to know what you're trying to accomplish with the **top.location.hash = '';** – harpo Mar 21 '11 at 21:29
  • Nothing actually. I just have a #hashLikeThis already in my address. When I click a specific element on my page i change the #hash to nothing so there is no confusion for the user. updated my post! – matt Mar 21 '11 at 21:33
  • Do you care if the browser reloads the page? – Peter Olson Mar 21 '11 at 22:01
  • possible duplicate of [javascript: completely remove top.location.hash?](http://stackoverflow.com/questions/5383591/javascript-completely-remove-top-location-hash) – Chris Jul 30 '12 at 09:19

1 Answers1

0

Just change the hash to something that is not significant and never used, e.g. an underscore. AFAIK, changing the hash to nothing will always scroll the page to the top.

Peter Olson
  • 139,199
  • 49
  • 202
  • 242
  • True, but he wants the hash to disappear. Only possible way to set top.location which will reload the page –  Mar 21 '11 at 21:41