views:

140

answers:

4

Hello,

I have added jQuery tabs to my upcomming site. So far no problem.

But I want - when clicking on a tab - that it should do and behave as a regular link.

Exampel 1: Look at this link http://jqueryui.com/demos/tabs/default.html. When clicking on the options:

  • Nunc tincidunt
  • Proin dolor
  • Aenean lacinia

It loads the content from the same file and the URL is static (default.html).

I want the following:

Exampel 2: When clicking on

  • Nunc tincidunt (ex. nunc.php)
  • Proin dolor (ex. proin.php)
  • Aenean lacinia (ex. aenean.php)

I want the hole page to re-load. Clicking on the tab "Nunc tincidunt" should load nunc.php (and the URL should be changed), clicking on "Proin dolor" should load proin.php and so on.

How should I accomplish this?

A: 

Hi,

Are you wanting to pull the content via ajax? If so this should help:

http://jqueryui.com/demos/tabs/ajax.html

elspiko
A: 

I'm not sure what you want it to do, but if it should open the link as a new page/replacement for the current page, the documentation explains:

[How to...] ...follow a tab's URL instead of loading its content via ajax

Note that opening a tab in a new window is unexpected, e.g. inconsistent behaviour exposing a usablity problem (http://www.useit.com/alertbox/tabs.html).

$('#example').tabs({
    select: function(event, ui) {
        var url = $.data(ui.tab, 'load.tabs');
        if( url ) {
            location.href = url;
            return false;
        }
        return true;
    } });

See http://jqueryui.com/demos/tabs/#...follow_a_tab.27s_URL_instead_of_loading_its_content_via_ajax

MvanGeest
I think there maybe is bieng some sort of confliction of the way I use it with my structure of my website.Let me explaine.I have header.php, footer.php -file which i include like the following in my files. Example:file: add-user.php<?PHP include('header.php');// Content goes here include('footer.php');?>In the header I have my jQuery tabs. But when implementing the header.php in each file I get both the nice structured "jQuery tabs" and also just under a <ul><li> - list with the same links as in the "jQuery tabs" the <ul> -list hrefs work, but not the "jQuery tabs". How come?
Fredrik
Someone who have a clue?
Fredrik
what you experience is probably what I explained in my previous comment. Unwanted ajax call from jQuery. Did you find a solution ?
PowerKiKi
A: 

Surely it is a matter of replacing your has links (#) with your .php links and changing the ID of the links to not reference those of the tabs?

webfac
A: 

You can give the anchors real href attributes, like this:

<div id="tabs"> 
    <ul> 
        <li><a href="nunc.php">Nunc tincidunt</a></li> 
        <li><a href="proin.php">Proin dolor</a></li> 
        <li><a href="aenean.php">Aenean lacinia</a></li> 
    </ul>
</div>​​​​​​​​​​

This will by default try and load those pages via AJAX into the corresponding tab. To prevent this behavior, just change the window.location yourself in the select event, like this:

$("#tabs").tabs({
    select: function(event, ui) {
       window.location = $.data(ui.tab, 'href.tabs');
    }
});​​​​​​​

You can give it a try here (note though you'll get unexpected/404 pages, since those PHP files aren't present on jsfiddle)

Nick Craver
This will not work as jQuery will select the first tab on initialization thus try to load via ajax the first url (nunc.php). You can confirm this behavior in your sample by watching net activity in firebug. If the page exists, you'll get funny effects such as recursive webpage if the first tab links on itself.We would need a way to totally deactivate ajax. But it looks like we cannot anymore...
PowerKiKi