Results 1 to 9 of 9

Thread: jQuery UI - Tab Issues

  1. #1

    Thread Starter
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    jQuery UI - Tab Issues

    Hi guys.

    This has been irritating me for a while so hopefully someone here can help me out with it.

    I'm setting up a tab bar where I want each tab to open the URL in the current page (not via ajax). I've tried the code given in the jQuery UI documents:

    Code:
    $(function() {
      $('#tab-bar').tabs({
        select: function(event, ui) {
          var url = $.data(ui.tab, 'load.tabs');
          if (url)
          {
            location.href = url;
            return false;
          }
          return true;
        }
      });
    });
    But it doesn't seem to work. When the tab is clicked, the URL does not load in the current page and instead the AJAX preview still shows. Any idea what could be going on here?
    My Blog.

    Ryan Jones.

  2. #2
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: jQuery UI - Tab Issues

    Hmm, just tried it myself and had no problems. Could you post your markup perhaps?

  3. #3

    Thread Starter
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: jQuery UI - Tab Issues

    Sure. You can see the test page here.
    My Blog.

    Ryan Jones.

  4. #4
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: jQuery UI - Tab Issues

    This is a guess, but it may be problematic that you're loading the home page into the first tab on the home page. As a result, after it loads, there are two elements with id="tab-bar", and the loaded-in home page will run your jQuery again and mess things up.

    Try using very simple pages for the tab links (like just "<p>Hello World</p>") to test things out.

  5. #5

    Thread Starter
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: jQuery UI - Tab Issues

    You could have a point there but I was hoping to have the "home" page displayed first. Hmm. I'll have to figure out how to do that another way since that seems to have solved it. Thanks for the tip.

    Do you know of a way to make it so that none of the tabs load their content automatically?

    Cheers.
    Last edited by sciguyryan; Dec 15th, 2009 at 12:46 PM.
    My Blog.

    Ryan Jones.

  6. #6
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: jQuery UI - Tab Issues

    I'm not really familiar with this plugin, so I don't know how to stop the auto-loading, but it may be more beneficial to work around it instead...

    I've found that this is actually a frequent "problem" when using AJAX - needing pages to load in one way when requested directly, and in another way when requested via AJAX. I don't know if this is the best approach, but I deal with it by setting up my AJAX-loaded pages like this:
    Code:
    <?php
    //include any globally necessary files
    require_once("global-file.php");
    
    //make a function that shows the page's content
    function writePage(){
      ?>
      <h1>Hello, this is my page</h1>
      <p>Paragraph!</p>
      <?php
    }
    
    //if the page was requested by AJAX, just spit out the content and stop here
    if(isset($_GET['ajaxCall'])){
      writePage();
      exit;
    }
    
    //otherwise, continue with the page as normal
    ?>
    <html>
    <head>
    <!-- etc. -->
    
    <?php
    //echo the content here as well, for when this page is requested normally
    writePage();
    ?>
    
    </body>
    </html>
    It may not be entirely intuitive, but it works. You'd need to append the "ajaxCall" (or whatever you want to call it) variable to your page requests, which you could do like so:
    Code:
    $('#tab-bar ul a').each(function(){
      var newURL = $(this).attr("href") + "?ajaxCall=1";
      $(this).attr("href",newURL)
    });
    It's important to append the variable via Javascript rather than manually adding it yourself, because you only want the variable to be there if Javascript is enabled.

  7. #7

    Thread Starter
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: jQuery UI - Tab Issues

    That's an interesting solution SambaNeko. I was thinking of something along those lines myself actually. I've had similar problems with AJAX in the past and found solutions like that to be invaluable.
    My Blog.

    Ryan Jones.

  8. #8

    Thread Starter
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: jQuery UI - Tab Issues

    I'm having more issues with the jQuery UI tabs than I wanted so I think I'll do the long way around and write my own tab system.
    My Blog.

    Ryan Jones.

  9. #9
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: jQuery UI - Tab Issues

    If you Google "jquery tabs" you can find others' implementations that may be more suitable to your needs. Or you can certainly write your own.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width