{"id":1051,"date":"2015-12-05T22:25:49","date_gmt":"2015-12-06T06:25:49","guid":{"rendered":"http:\/\/blog.portnumber53.com\/?p=1051"},"modified":"2015-12-05T22:25:49","modified_gmt":"2015-12-06T06:25:49","slug":"bootstrap-prevent-jump-to-content-when-clicking-tabs","status":"publish","type":"post","link":"https:\/\/blog.portnumber53.com\/index.php\/2015\/12\/05\/bootstrap-prevent-jump-to-content-when-clicking-tabs\/","title":{"rendered":"Bootstrap: prevent jump to content when clicking tabs"},"content":{"rendered":"<p>\n\tRecently I had to add tabs to a website and ran into not wanting the browser to jump to the panel content when tabs are clicked. I just want the content to switch.\n<\/p>\n<p>\n\tAfter a little research, I found posts explaining how to obtain the opposite, and a little later found this:\n<\/p>\n<p>\n\t<a href=\"http:\/\/blog.shaunscovil.com\/post\/55630727782\/twitter-bootstrap-how-to-prevent-jump-when-tabs-are-clic\" target=\"_blank\" rel=\"noopener\">http:\/\/blog.shaunscovil.com\/post\/55630727782\/twitter-bootstrap-how-to-prevent-jump-when-tabs-are-clic<\/a>\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\tAfter giving their suggestion a try, I noticed that the path part of the URL was not being preserved (it could as well be something else on my javascript code), but anyways, here&#39;s what I have now:\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<pre style=\"background-color:#0b0b0b;color:#a9b7c6;font-family:'Monoid';font-size:10.5pt;\">\n<span style=\"color:#808080;\">\/\/ Change hash for page-reload\n<\/span><span style=\"color:#cc7832;font-weight:bold;\">var <\/span>url = document.location.toString()<span style=\"color:#cc7832;\">;\n<\/span><span style=\"color:#cc7832;font-weight:bold;\">if <\/span>(url.match(<span style=\"color:#6a8759;\">&#39;#&#39;<\/span>)) {\n    $(<span style=\"color:#6a8759;\">&#39;.nav-tabs a[href=#&#39; <\/span>+ url.split(<span style=\"color:#6a8759;\">&#39;#&#39;<\/span>)[<span style=\"color:#6897bb;\">1<\/span>] + <span style=\"color:#6a8759;\">&#39;]&#39;<\/span>).tab(<span style=\"color:#6a8759;\">&#39;show&#39;<\/span>)<span style=\"color:#cc7832;\">;\n<\/span>} <span style=\"color:#cc7832;font-weight:bold;\">else <\/span>{\n    $(<span style=\"color:#6a8759;\">&#39;.nav-tabs a[href=#tab_account]&#39;<\/span>).tab(<span style=\"color:#6a8759;\">&#39;show&#39;<\/span>)<span style=\"color:#cc7832;\">;\n<\/span>}\n$(<span style=\"color:#6a8759;\">&#39;.nav-tabs a&#39;<\/span>).on(<span style=\"color:#6a8759;\">&#39;shown.bs.tab&#39;<\/span><span style=\"color:#cc7832;\">, <\/span><span style=\"color:#cc7832;font-weight:bold;\">function <\/span>(e) {\n    <span style=\"color:#cc7832;font-weight:bold;\">var <\/span>url = document.location.toString()<span style=\"color:#cc7832;\">;\n<\/span><span style=\"color:#cc7832;\">    <\/span><span style=\"color:#cc7832;font-weight:bold;\">if <\/span>(url.match(<span style=\"color:#6a8759;\">&#39;#&#39;<\/span>)) {\n        <span style=\"color:#808080;\">\/\/$(&#39;.nav-tabs a[href=#' + url.split('#')[1] + ']&#39;).tab(&#39;show&#39;);\n<\/span>\n<span style=\"color:#808080;\">        <\/span>url = url.split(<span style=\"color:#6a8759;\">&quot;#&quot;<\/span>)[<span style=\"color:#6897bb;\">0<\/span>]<span style=\"color:#cc7832;\">;\n<\/span><span style=\"color:#cc7832;\">    <\/span>}\n    history.pushState( <span style=\"color:#cc7832;font-weight:bold;\">null<\/span><span style=\"color:#cc7832;\">, <\/span><span style=\"color:#cc7832;font-weight:bold;\">null<\/span><span style=\"color:#cc7832;\">, <\/span>url + $(<span style=\"color:#cc7832;font-weight:bold;\">this<\/span>).attr(<span style=\"color:#6a8759;\">&#39;href&#39;<\/span>) )<span style=\"color:#cc7832;\">;\n<\/span>})<span style=\"color:#cc7832;\">;<\/span><\/pre>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\tHopefully that telps someone else.\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently I had to add tabs to a website and ran into not wanting the browser to jump to the panel content when tabs are clicked. I just want the content to switch. After a little research, I found posts explaining how to obtain the opposite, and a little later&#8230; <a class=\"continue-reading-link\" href=\"https:\/\/blog.portnumber53.com\/index.php\/2015\/12\/05\/bootstrap-prevent-jump-to-content-when-clicking-tabs\/\"> Continue reading <span class=\"meta-nav\">&rarr; <\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[110,200,332],"class_list":["post-1051","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-disable-scroll","tag-jquery","tag-tab"],"_links":{"self":[{"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/posts\/1051","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/comments?post=1051"}],"version-history":[{"count":0,"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/posts\/1051\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/media?parent=1051"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/categories?post=1051"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/tags?post=1051"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}