Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

loading new page in tabs using twitter bootstrap

Hi I am using the following code to create tabbed layout using twitter bootstrap

<ul class="nav nav-tabs" >
   <li class="active"><a href="#"  data-toggle="tab">Request Audit</a></li>
   <li><a href="#" data-toggle="tab">status</a></li>
   <li><a href="#" data-toggle="tab">Settings</a></li>
   <li><a href="#" data-toggle="tab">Help</a></li>
</ul>

now in all tabs i need different page to load.So i want to do this :

<ul class="nav nav-tabs" >
       <li class="active"><a href="#"  data-toggle="tab">Home</a></li>
       <li><a href="status.html" data-toggle="tab">status</a></li>
       <li><a href="settings.html" data-toggle="tab">Settings</a></li>
       <li><a href="help.html" data-toggle="tab">Help</a></li>
</ul>

I don't want to load the content from same page in all tabs and above code is not loading new page.Please help..

update :

<ul class="nav nav-tabs" id="myTab">
  <li class="active"><a href="#audit">Request Audit</a></li>
  <li><a href="#status">status</a></li>
  <li><a href="#settings">Settings</a></li>
  <li><a href="#help">Help</a></li>
</ul>

<div class="tab-content">
  <div class="tab-pane active" id="audit">
    <p>audit</p>
  </div>
  <div class="tab-pane" id="status">
     <p>status</p>
  </div>
  <div class="tab-pane" id="settings">
      <p>settings</p>
  </div>
  <div class="tab-pane" id="help">
      <p>help</p>
  </div>
</div>

I have added this script

<script>  

   $('#myTab a[href="#status"]').click(function (e) {
         e.preventDefault();
         $(this).tab('show');
         $('#status').load('status.html');
   });
</script>
like image 233
vishesh Avatar asked Sep 16 '12 17:09

vishesh


2 Answers

Just remove the data-toggle="tab"

for example: on the Home Page:

<ul class="nav nav-tabs" >
       <li class="active"><a href="#" >Home</a></li>
       <li><a href="status.html" >status</a></li>
       <li><a href="settings.html" >Settings</a></li>
       <li><a href="help.html" >Help</a></li>
</ul>
<div class="tab-content">
     <div class="tab-pane active" id="tab1">
         <p>Home Page content 1</p>
     </div>
</div>​

On the status.html page:

<ul class="nav nav-tabs" >
       <li ><a href="#" >Home</a></li>
       <li class="active"><a href="status.html" >status</a></li>
       <li><a href="settings.html" >Settings</a></li>
       <li><a href="help.html" >Help</a></li>
</ul>
<div class="tab-content">
     <div class="tab-pane active" id="tab1">
         <p>status content 1</p>
     </div>
</div>​

The bad thing is just have some copy of the nav-tab codes

like image 86
gfan Avatar answered Oct 11 '22 13:10

gfan


There are several ways to do this, but before deciding which one to use, I'd want to make sure you actually want to piece out your files like that. What's keeping you from just putting the content inside of the tabs on the page as it is?

If not, why not use PHP?

If you decide to stick with your current plan, the way I'd accomplish what you're looking to do would be through jQuery and AJAX.

First, you want to make sure you're using the proper Bootstrap structure – check out the Tabbable Nav section, and make your markup tabs correspond to empty content areas:

       <div class="tabbable" style="margin-bottom: 18px;">
          <ul class="nav nav-tabs">
            <li class="active"><a href="#tab1" data-toggle="tab">Request Audit</a></li>
            <li class=""><a href="#tab2" data-toggle="tab">Status</a></li>
            <li class=""><a href="#tab3" data-toggle="tab">Settings</a></li>
            <li class=""><a href="#tab4" data-toggle="tab">Help</a></li>
          </ul>
          <div class="tab-content" style="padding-bottom: 9px; border-bottom: 1px solid #ddd;">
            <div class="tab-pane active" id="tab1">
              <p>Placeholder 1</p>
            </div>
            <div class="tab-pane" id="tab2">
              <p>Placeholder 2</p>
            </div>
            <div class="tab-pane" id="tab3">
              <p>Placeholder 3</p>
            </div>
            <div class="tab-pane" id="tab4">
              <p>Placeholder</p>
            </div>
          </div>
        </div>​

Then, use jQuery.load to fill in the tab-panes!

$('#tab2').load('/status.html');
$('#tab3').load('/settings.html');
$('#tab4').load('/help.html');
like image 30
crowjonah Avatar answered Oct 11 '22 13:10

crowjonah