Jump to content
Sign in to follow this  
Nathan

Linking to Tabs

Recommended Posts

I'm using the following bootstrap method for tabs.

<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
  <li class="active"><a href="#home" role="tab" data-toggle="tab">Home</a></li>
  <li><a href="#profile" role="tab" data-toggle="tab">Profile</a></li>
  <li><a href="#messages" role="tab" data-toggle="tab">Messages</a></li>
  <li><a href="#settings" role="tab" data-toggle="tab">Settings</a></li>
</ul>

<!-- Tab panes -->
<div class="tab-content">
  <div class="tab-pane active" id="home">...</div>
  <div class="tab-pane" id="profile">...</div>
  <div class="tab-pane" id="messages">...</div>
  <div class="tab-pane" id="settings">...</div>
</div>

My question is how can I link to a tab so when you go to that link the page opens in that tab?

http://domain.com/index.php#profile for example does not open into the profile tab.

Share this post


Link to post
Share on other sites

Fixed by adding this just before the closing </body> tag.

<script>
$(function() {
     hashtag=window.location.hash
     if(hashtag!=""){
          $('.nav-tabs a[href='+hashtag+']').tab('show')	
     }
})
</script>

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...