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!
There isn’t a way to prevent the default hash behavior, but you can alter your hash scheme so the #tag doesn’t correspond to any ID on your page. On page load, take the hash value and append a constant (ex:
_hash), then scroll to that using jQuery.Example:
http://mysite/page.php#tab4
page.php has
<div id="tab4_hash"></div>On page load, get the div by doing
tab4+_hash