Update: The solution I posted does not fix the problem I described ^^ will post again if I remember when I solve it.
Update2: I've "solved" the problem for now (see below).
Question is a bit old, but if anyone stumbles on this question as I did, a quick change to the above solution by Justin Hamade might help some people.
If you use Jquery Address' externalChange event instead of just "change" it prevents sending a superfluous request (in my case resulting in a error in the javascript console). This is because if someone clicks a tab the address changes on its own (thanks to jquery ui), thsi change triggers $.address.change once, which selects a tab even though jquery-ui has already done so... At least I think thats what was going on.
Also I did not like the tabs creating hashes like "#ui-tab-2", "#ui-tab-3" etc, so I used the following code which makes the urls use the names of the anchor elements as the hashes (i.e. "www.example.com#cool_stuff" instead of "www.example.com#ui-tab-2"):
$(function() {
$( "#tabs" ).tabs({
cache: false,
});
// For forward and back
$.address.externalChange(function(event){
var name = window.location.hash != "" ? window.location.hash.split("#")[2] : ""
$("#tabs").tabs( "select" , $("#tabs a[name="+ name + "]").attr('href') )
});
// when the tab is selected update the url with the hash
$("#tabs").bind("tabsselect", function(event, ui) {
$.address.hash(ui.tab.name);
});
});
However, A) I'm new to jquery and not sure this is efficient / safe / "The Right Way To Do It", and B) Be sure to use this only if you can be sure the 'name' attribute of the anchors does not have any characters that are not URI safe (i.e. space).
Update2: I've "solved" the problem in Update1 for now, but it has the terribly ugly line:
var name = window.location.hash != "" ? window.location.hash.split("#")[2] : ""
Because apparently the $.address.hash(val) function adds a "/#" after the first hash, but if we don't use the $.address.hash(val) then externalChange is triggered (by window.location.hash=val)