Created by: Robadob
history.pushState
updates the browser history and address bar.
I found it unusual that the functionality of pressing tabs updating the address bar to this url was unavailable, so that tabs could be more easily treated as a single page nav. I understand this behaviour isn't always necessary, hence the optional usage by adding follow-url
as an attribute to the anchor which is used to show the tab.
Loading the correct tab then works something like this where all tab anchors have .my_tabs
$(document).ready(function(){
$address=document.URL;
if($address.replace(/^[^#]*/, "").length==0)
$address=$address+$(".my_tabs.active").attr("href");
$selector = $address.replace(/^[^#]*/, "");
$(".phase_link").each(
function( index ) {
if ($selector == $(this).attr("href"))
$(this).tab("show");
}
);
});
history.pushState
is HTML5 so wont work in older browsers, however this functionality is implemented at the end of the show method so any javascript error caused by it would't break the primary functionality of tabs. If it were desired for this to implemented for older browsers this stackoverflow post suggests a method which I haven't tested; http://stackoverflow.com/a/136506/1646387