Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the hash but not moving the page using jquery ui tabs

Tags:

hash

jquery-ui

I added the following code to change the hash to the tab name:

$("#tabs > ul").tabs({ 
select: function(event, ui){ 
window.location.hash = ui.tab.hash; 
} 
} );

This works fine in FF3 but in IE7 it moves down the page (depending on the tab selected anywhere from somewhere near the top of the page all the way down to the very end of the page).

I tried changing it to:

$("#tabs > ul").tabs();
$("#tabs > ul").bind("tabsshow", function(event, ui) {
window.location = ui.tab.hash;
})

This leads to identical behavior in both IE7 and FF3, which moves the page down to the top of the selected tab.

I would like the tab to be changed, the hash to be updated, but the page not moved at all, which is how it works in FF3 in my first example, but not in IE7.

Thanks.

Notes: JQuery 1.3.1 / JQuery-UI 1.6rc6

like image 924
Rob Avatar asked Dec 14 '25 19:12

Rob


1 Answers

If there's an element on the page that has the same id as what you're setting the hash to, for instance you're trying to set the browser hash to #cars and there's already a div#cars on the page, the browser will scroll you down to where that div is.

To my knowledge, there are 3 possible workarounds

1) Change the browser hash to something else such as #thecars.

2) Change your existing markup in some similar manner.

3) On some event, changing the id of your similarly named markup, then changing the browser hash, then rechanging the name of markup back to it's original value should also theoretically work. This is obviously a bad and slow workaround, just thought I'd mention it.

like image 198
CPrimer Avatar answered Dec 16 '25 23:12

CPrimer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!