using jQuery address plug in and window.location update without executing address.change twice
I have two events that need to be executed in this order:
tabs toggled into/out of view
the browser navigating to a hash tag as it would normally (jumping down the page to the anchor)
And I need it to work with the back button.
I wrote my own function gotoanchor()
which accomplishes the first two and because I am navigating to the page using location.href
the move is added to the browser history by the browser.
I need jQuery to intercept the back/forward buttons and let me hide/show the tabs before scrolling the page.
The most hopeful looking plug in I've found is jQuery Address
This is my code as it stands:
$("a[href^=#]")开发者_如何学运维.click(function(){
gotoanchor(this.hash);
return false;
});
$.address.externalChange(function(event) {
// do something depending on the event.value property, e.g.
gotoanchor(event.value);
});
I'm having 3 problems:
the
location.href
update is considered an externalChange by address and it executes the code in response to it. I can't just let address manage the history because it doesn't scroll down the page to where the hash is.address wants to update the hash on it's own too. The API is quite extensive and I'm reasonably sure there's a way to tell it not to but the documentation could use some work.
it's adding #/#hash to my URL and I'd rather it was just #hash
Thanks!
精彩评论