Prevent default hash behavior on page load

Viewed 22349

I have a page with a tabbed interface. Each tab has a unique id. I've enabled links pointing to that page with the appended id after the hash, and I'm now trying to circumvent the default browser behavior that opens a URL with hash at the location of the element on the page.

So:

  • pageA links to pageB like this: <a href="pageB.php#Tab4">Go</a>
  • pageB opens, and my jQuery activates the correct tab, but the browser has scrolled down to where <div id="Tab4"> is located on the page.

That's exactly what I want to prevent.

Any ideas? Thanks!

4 Answers

After you're done loading the right tab, run this:

window.location = '#';
Related