I encountered a rather frustrating problem with jQuery UI tabs this week. The problem occurs when trying to tabify some content after using jQuery’s $().load method to load the tabs HTML via an ajax request.

The following code works perfectly in all browsers except IE6 and IE7 (It works fine in IE8 as well), as can be seen in the screenshot below.

$('#deviceDetailsWrapper').load('/device/details/294', null, function() {
    $('#tabs').tabs();
});

image

However, here is what renders in IE6/7. For some reason, the jQuery tabs are triggering a GET request of the current URL and loading the content into the tab itself. Below you are actually seeing the entire page loaded inside the tab. I discovered this by inspecting the DOM tree within the tab in Firebug, as well as loading up Fiddler and watching the tab call an entirely separate GET request to the current URL as soon as the tabs were loaded. Strange behavior to me, since I am not entirely familiar with the jQuery tabs.

image

The Solution

The only thing I discovered was different regarding the .tabs() DOM manipulation in the different browsers was the ID of the tab – instead of being the #tab-id that I named it, the element was being assigned the full URL+#id to the container. So “#tab1” was becoming “http://localhost/device#tab1” – which I believe was triggering the tabs to behave in their “ajax” mode, which is a built-in feature of the jQuery tabs.

The solution I found was opening up jquery.ui.all.js and locating the following code:

this.$tabs.each(function(i, a) {
var href = $(a).attr('href');

// inline tab
if (fragmentId.test(href))
    self.$panels = self.$panels.add(self._sanitizeSelector(href));
Replace it with the following:
this.$tabs.each(function(i, a) {
var href = $(a).attr('href');
            
// Fix tab IDs in IE6/7
href = href.substring(href.indexOf("#"));

// inline tab
if (fragmentId.test(href))
    self.$panels = self.$panels.add(self._sanitizeSelector(href)); 

Hopefully this helps someone in their googling of this problem. I will be logging this as a bug with the jQuery developers.

Comments

# re: jQuery UI 1.6rc6 tabs bug with IE6/7

Gravatar
Nico
2/23/2009 3:35 AM
Thank you very very much!
This is fixing many problems on primoo.net :)
I spended more than 2 Days by trying to fix the tabs-problem with dynamicly inserted content on ie6, but found no answer...

you're my hero! :)

cu, nico

# re: jQuery UI 1.6rc6 tabs bug with IE6/7

Gravatar
mhidinger
2/23/2009 10:03 AM
I'm glad it helped, I went through the same thing for a few hours struggling to pinpoint the problem.

# re: jQuery UI 1.6rc6 tabs bug with IE6/7

Gravatar
frank
3/3/2009 7:27 PM
great work!

# re: jQuery UI 1.6rc6 tabs bug with IE6/7

Gravatar
Shane Kempton
3/5/2009 2:43 PM
Great Find and very helpful. We actually fixed it by finding the offending a tags and stripped the URL right before we call the load Tabs. This kept us from having to dig into the jQuery files, since we only had one place it needed to be fixed.

# re: jQuery UI 1.6rc6 tabs bug with IE6/7

Gravatar
cosinus
4/4/2009 9:06 AM
I tried you fix I still has a problem
My jquert Tab works with ie7 and Firefox, but I not appears in ie6 !
any suggestions ?

# re: jQuery UI 1.6rc6 tabs bug with IE6/7

Gravatar
lol
4/13/2009 8:25 AM
Thanks Brother you saved my day!!!

# re: jQuery UI 1.6rc6 tabs bug with IE6/7

Gravatar
mounir.dz
4/14/2009 3:53 AM
Thanks you , great work!
should be updated in the last verssion of ui :).

# re: jQuery UI 1.6rc6 tabs bug with IE6/7

Gravatar
Aaron
5/28/2009 8:35 AM
Cool, I'll have to try this out. Thanks

# re: jQuery UI 1.6rc6 tabs bug with IE6/7

Gravatar
download roulette games online
7/17/2009 3:20 AM
Thanks for the post. I had high expectations for this but in your demo, for tabs, why doesnt the selected tab get the orange background? I tried doing this on my local page, in IE6, but the rounded corner does not work on the SELECTED tab. Is this a known bug of this technique or is there a workaround?

# re: jQuery UI 1.6rc6 tabs bug with IE6/7

Gravatar
varun
8/5/2009 6:59 AM
Dear,

I m using jquery tab plugin.

but when ever i do some post back from a tab

the layout of the page becomes change (all tabs show in sequence one after another.)

so please tell me how to maintain the layout of the page.
Comments have been closed on this topic.