An upgrade to the jQuery Thickbox Plugin

I have been doing a lot of work in jQuery as of late and stumbled across the popular jQuery plugin called "Thickbox" which works similarly to Lightbox, but is more fully featured.

ThickBox is a webpage UI dialog widget written in JavaScript on top of the jQuery library. Its function is to show a single image, multiple images, inline content, iframed content, or content served through AJAX in a hybrid modal.

There were a couple of problems with the plugin though when I started using it. For one, the plugin has not been updated in a long time and was not compatible with the latest version of jQuery: 1.3.1. It also used a rather non-standard way of configuration and was completely non-extensible. In fact, it required users to edit CSS and Javascript files in order to point the library at the right images to use. That's no good at all because it makes it possible for a simple upgrade to break a site, granted in a minor way, but still.

No doubt the original author of the plugin has a million other things on his plate, so I thought I would chip in, upgrade the plugin, and contribute them back to the author and community, and if necessary take over maintenance of the plugin.



Installation Instructions

  1. Upload the thickbox files to your web server.

  2. In your web page using thickbox, import the javascript like so:

    <script type="text/javascript" src="jquery.thickbox-byrne.js"></script>
  3. In your web page, import the CSS like so:

    <link rel="stylesheet" href="thickbox.css" type="text/css" />
  4. Read the rest of this documentation and initialize thickbox according to your needs.


The following options can be used when initializing Thickbox.

  • macFFBgHack - default: '../images/macFFBgHack.png'. A path to the image "macFFBgHack.png" on your web server.

  • loadingImage - default: '../images/thickbox-loading.gif'. A path to the image "thickbox-loading.gif" on your web server.

  • modal - boolean (true|false), default: false. Determines whether or not the dialog that appears is modal or not.

  • iframe - boolean (true|false), default: false. Determines whether or not the dialog will be iframed content.

  • inlineId - string, default: ''. Sets the DOM id that contains the content that will be displayed in the thickbox.

  • width - default: 600. Sets the size (width obviously) of the thickbox.

  • height - default: 400. Sets the size (height obviously) of the thickbox.


            macFFBgHack: 'images/macFFBgHack.png',
            loadingImage: 'images/thickbox-loading.gif'


It worked!

Click me

Changes between 1.3 and 1.3-byrne

The version described here is '1.3-byrne' which is a fork of the original Thickbox plugin versioned 1.3. Here is a list of the changes I have made in my fork:

  • thickboxes can be instantiated on any element ID now. It is no longer hard-coded to $("a.thickbox").
  • thickboxes are now configured using a more standard settings/options array.
  • The plugin itself now utilizes more a more up-to-date coding standard for jQuery plugins.
  • The plugin is now compatible with jQuery 1.3 and greater.

Recommended Entries


This is going to be some fantastically bad timing, but you should have a look at the Thickbox Reloaded version Klaus Hartl created a while back, in part because the original wasn't being worked on.

He made several programmatic and styling fixes and I can't remember whether or not they were all integrated with Cody's original when he did eventually do an update. Most importantly, though, it also implemented a way to assign the TB action to a jQuery selector(making it more "plugin-like"), so that authors wouldn't have to add the class="thickbox" every single time, and that definitely wasn't picked up by Cody. You can find Klaus' version in the jQuery Google Code project under trunk/plugins. You'll have to check the code out; the web interface only shows a partial listing for that dir. I'm having trouble finding the post--or I suspect e-mail--where Klaus went over all the details of what he changed, but here's a start.

Aaaaaand on re-scan it looks from the usage snippet like you did your own implementation of the selector bit. The usage snippet was still referring a.thickbox and I glossed. At any rate, it might still be worth a peek at what Klaus did in case there's anything interesting.

I should absolutely merge his changes in. Too bad I didn't look harder for work someone else had done. On the plus side it looks like are changes are compatible so they should be easy to merge in.

Hi Byrne,

I used this thing somewhile ago. Glad you've made for MT4. But I cannot see the code which you are mentioning in bullet 2 and 3..... Do I miss something?

Nope - I made a mistake in my Markdown. Thanks for pointing out the problem.

BTW - this is not for Movable Type. This is a generic jQuery plugin.

I noticed you now assigned the path of macFFBgHack and loadingImage into the thickbox.js and a global JS file.

I'm not a programmer so I'd like to know; why is there a need to assign the image path in both JS files now?

BTW, your comment form kept saying I needed to input my email and URL when I've already did - in Chrome.

There should be no need to specify the paths to the loadingImage and macFFBgHack directly in the javascript files anymore. You should specify those only through the allotted configuration parameters.

How can I use this upgrade to load a thickbox when my page is fully loaded ?

I used to simply do :

$(document).ready(function(){ tb_show('title','myUrl',null); }

this no longer seems to work.

This is how that function call will translate to the new system:



$(document).ready(function() {

This will trigger the thickbox when you click the a link with a class of thickbox. Are you trying to trigger it on page load?

I am having the same problem with triggering the thickbox on page load.

How would I be able to do this using the new system?

The iframe portion doesnt work. Its trying to call tb_showIframe but cannot find the function.

So is there any way to get this to work with iframe content and to get it to work on load?

Does not work on IE7 or IE8, almost 30% of the lower part of the thickbox window is not visible, even if you scroll down it will not appear...

I can't seem to get this to work after replacing the .js file and .css file from thickbox 3.1. Now it just follows the link and loads the target page (FF and IE). Is this only for .php or can it also be used in .aspx pages? My link is as follows:

<a href="page.aspx?height=600&width=950&modal=true" class="thickbox" title=""> Test </a>

If this is wrong, could you post an example usage?

Thanks for pointing out the problem

I too was having the issue with the iframe not working. The problem is that the iframe has an onload event attached that calls the tb_showIframe() function. Since the functions are all wrapped up in the plugin this caanot be called.

To fix the problem make the following change (approx. line 222):

} else if (settings.iframe) { tbposition(); tbshowIframe(); }

You can remove the "Safari fix" part, as it is basically doing the same thing as tb_showIframe() anyway.

I attached an updated zip with the changes to the ticket for this bug. If you want, go grab it:

Woops. Looks like the js layout got chewed up. Grab the updated zip for the proper fix.

This doesn't solve my main gripe with thickbox. The most basic operation is to flash up an image in the middle of the screen, with html like:

If this code happens to be at the bottom of a long page - more than a scroll down - then the full image pops up at the top of the page - where the user has to scroll up to look for it.

Is there a solution to this?

OK, I'm wrong. Something is messing with me, but it's not thickbox.

Leave a comment

what will you say?

Recent Comments