{"id":99,"date":"2009-10-30T15:45:17","date_gmt":"2009-10-30T21:45:17","guid":{"rendered":"http:\/\/benincosa.com\/blog\/?p=99"},"modified":"2014-11-19T11:26:55","modified_gmt":"2014-11-19T17:26:55","slug":"jquery-ui-tabs-and-the-back-button","status":"publish","type":"post","link":"https:\/\/benincosa.com\/?p=99","title":{"rendered":"jquery ui tabs and the back button"},"content":{"rendered":"<p>For the site I help out with, xcat.sf.net, I used jquery-ui tabs.\u00a0 The only issue I had was that I couldn&#8217;t do back button, and I started getting a few complaints from it&#8230;<\/p>\n<p>So, after about 20 minutes of investigation, here is the code I used to make it work.\u00a0 It works pretty well for cases when you navigate externally, but doesn&#8217;t work when you press the back button while on the page, expecting to go to the previous tab.\u00a0 The jQuery team says that they&#8217;re working on this but its not in there today. Also, my approach refreshes the entire page with each click, that&#8217;s how I get the right page.\u00a0 So it may not be optimal for many places.\u00a0 Anyway, here is what I do:<\/p>\n<p>&lt;script type=&#8221;text\/javascript&#8221;&gt;<br \/>\n$(document).ready(function(){<br \/>\nvar start = window.location.href.lastIndexOf(&#8220;#&#8221;);<br \/>\nvar tabIndex = 0;<br \/>\nif (start !== -1){<br \/>\ntabIndex = window.location.href.substring(start+1, start+2);<br \/>\n}<br \/>\n$(&#8216;#tabs&#8217;).tabs({<br \/>\nselected: tabIndex,<br \/>\nspinner: &#8216;Retrieving data&#8230;&#8217;,<br \/>\nselect: function(event,ui){<br \/>\nwindow.location = &#8220;#&#8221; +\u00a0 ui.index;<br \/>\nwindow.location.reload();<br \/>\n},<br \/>\n});<br \/>\n});<br \/>\n&lt;\/script&gt;<\/p>\n<p>Then, down below in the HTML, I have:<\/p>\n<p>&lt;div id=&#8217;tabs&#8217;&gt;<br \/>\n&lt;ul&gt;<br \/>\n&lt;li&gt;&lt;a href=&#8221;about.html&#8221;&gt;About&lt;\/a&gt;&lt;\/li&gt;<br \/>\n&lt;li&gt;&lt;a href=&#8221;download.html&#8221;&gt;Download&lt;\/a&gt;&lt;\/li&gt;<br \/>\n&lt;li&gt;&lt;a href=&#8221;start.html&#8221;&gt;Getting Started&lt;\/a&gt;&lt;\/li&gt;<br \/>\n&lt;li&gt;&lt;a href=&#8221;docs.html&#8221;&gt;Documentation&lt;\/a&gt;&lt;\/li&gt;<br \/>\n&lt;li&gt;&lt;a href=&#8221;support.html&#8221;&gt;Support&lt;\/a&gt;&lt;\/li&gt;<br \/>\n&lt;li&gt;&lt;a href=&#8221;test.html&#8221;&gt;Testimonials&lt;\/a&gt;&lt;\/li&gt;<br \/>\n&lt;\/ul&gt;<br \/>\n&lt;\/div&gt;<\/p>\n<p>That makes it so that the back button is supported.\u00a0 It changes the URL a bit, by giving it a nasty #&lt;tabindex&gt; but it does the trick for me.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For the site I help out with, xcat.sf.net, I used jquery-ui tabs.\u00a0 The only issue I had was that I couldn&#8217;t do back button, and I started getting a few complaints from it&#8230; So, after about 20 minutes of investigation, here is the code I used to make it work.\u00a0 It works pretty well for&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[40,1],"tags":[41],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/benincosa.com\/index.php?rest_route=\/wp\/v2\/posts\/99"}],"collection":[{"href":"https:\/\/benincosa.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/benincosa.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/benincosa.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/benincosa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=99"}],"version-history":[{"count":2,"href":"https:\/\/benincosa.com\/index.php?rest_route=\/wp\/v2\/posts\/99\/revisions"}],"predecessor-version":[{"id":101,"href":"https:\/\/benincosa.com\/index.php?rest_route=\/wp\/v2\/posts\/99\/revisions\/101"}],"wp:attachment":[{"href":"https:\/\/benincosa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=99"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/benincosa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=99"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/benincosa.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=99"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}