Feedback

About Designerfoo and Me!

I am Manoj Sachwani, a webmaster, wannabe illustrator, designer, developer, amongst other things. I have over 14 years of experience, developing, designing and deploying websites. I am geeky, hairy and and I love what I do.

I stumbled & bought this domain - Designerfoo.com - because I thought it would be a "cool" domain to have, as time went on, I realized that I want to become - "Designerfoo" - and grow my knowledge in design, illustration, web design and web development.

I am webmaster, I design and develop websites with an edge. How may I help you?
Contact   -   @designerfoo   -   Facebook
Who is

jQuery: Thickbox Hack to refresh parent window on tb_close() event

DesignerfooDevelopment + jQuery • 09-12
Comment(s)

I was looking for a way to refresh the parent window on the remove event [tb_remove()] of thickbox jQuery plugin, developed by Cody Lindley, with/without modal and/or iframe popup windows. And here is what I did, hope this helps you guys too…

Step 1

Get the unpacked/unminified version of ThickBox.js. Open it up in your favorite text editor and find this function in the file.

function tb_remove() {
$("#TB_imageOff").unbind("click");
$("#TB_closeWindowButton").unbind("click");
$("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay,
#TB_HideSelect').trigger("unload").unbind().remove();});
$("#TB_load").remove();
if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
$("body","html").css({height: "auto", width: "auto"});
$("html").css("overflow","");
}
document.onkeydown = "";
document.onkeyup = "";
return false;
}

Now depending on how you want the close links or thickbox’s remove/close function to behave, in all of your pop-ups, you can modify the function to take up a true/false parameter, which when set to true would refresh the parent window, and false wouldn’t. This would give you some control over which thickbox pop-ups would refresh the parent window – this is what I have done.

Step 2-A: Modifying the function to accept parameters to refresh the parent.

We just edit the function to accept a parameter, and check if the passed variable is true or false. If true, refresh the parent window, if false, don’t, just close the window.


function tb_remove(closeparentwindow) {
if(closeparentwindow){
parent.location.reload(1);
}

$("#TB_imageOff").unbind("click");
$("#TB_closeWindowButton").unbind("click");
$("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay,
#TB_HideSelect').trigger("unload").unbind().remove();});
$("#TB_load").remove();
if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
$("body","html").css({height: "auto", width: "auto"});
$("html").css("overflow","");
}
document.onkeydown = "";
document.onkeyup = "";
return false;
}

That’s all there is to it :)

Now when you call the function tb_remove(), just pass the boolean value to the function and voila your parent window would refresh.

Calling the tb_remove() function to close thickbox’s parent window.

<a href=”#” onclick=”window.parent.tb_remove(true);”>Close</a>

Step 2-B: Modifying the function to refresh parent, everytime any thickbox window is closed.

function tb_remove() {
parent.location.reload(1);
//just add this line without the if and without modifying
the function to accept parameters

$("#TB_imageOff").unbind("click");
$("#TB_closeWindowButton").unbind("click");
$("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay,
#TB_HideSelect').trigger("unload").unbind().remove();});
$("#TB_load").remove();
if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
$("body","html").css({height: "auto", width: "auto"});
$("html").css("overflow","");
}
document.onkeydown = "";
document.onkeyup = "";
return false;
}

Note: Step 2B The above will refresh the parent window every time any kind of thickbox popup is closed, iframe,modal, etc. and is only advised if you know what your are doing.

Step 3: Save and you are done.

Post Rating 3.00 out of 5


Subscrive via feedburner rss

Subscrive via feedburner email

Some info + resources

Thickbox.js is not maintained anymore, albeit you can still use it and it works wondersand is pretty simple. Here are some replacements, you might want to consider.
  • jQuery Lightbox
  • Shadowbox - Framework Independent
  • jQuery UI's dialog box
  • What to do Next?

    Read some related posts?
    3 Responses to “jQuery: Thickbox Hack to refresh parent window on tb_close() event”
    Comment History Slider
      April 27, 2010 at 1:20 pm
      Author: Ali

      hi, your page is so nice and helpful.
      can you tell me how i can Redirect to specific page rather than the Refresh parent window.

      April 21, 2010 at 10:33 pm
      Author: vero

      hey, if need to exec an ajax function to relaod only one div.
      And if i exec that function insted of the “reload” works fine, but when i click again to open something else, it opens in a new window. Any idea why?

      February 9, 2010 at 5:38 pm
      Author: jdg

      Thanks! Just what I was looking for. This should be part of thickbox.



    Leave a reply :)

    Name:

    (required)

    Mail (will not be published):

    (required)

    Website:

    Comment:


    Subscribe

    Deliverables

    • Website design/interface layout
    • CMS Theme-ing
    • Website/webapp/RIA Development
    • Website redesign
    • Webmaster services
    • Consultations on marketing/branding/etc over Coffee/beer/lunch/dinner

    My Value Proposition

    • Fast turn around times.
    • Free consultations on marketing and branding
    • Affordable services
    • Around the clock support.
    • An experience of over 14 years with providing these services.

    My services for barter.

    • If you think you might have something that I would use/want, I am ready to provide my services for $1.00 and a barter!

    Friends

    A thanks of gratitude to these guys. They are just plain awesome!

    Eventify – Simple Events

    NextGEN Resize Wordpress Plugin

    Categories

    Recent Posts

    Looking for something?

    Thanks to Subscribers

    Feedburner : 24


    Twitter : 2250

    Thank you for taking the time out.

    Your Email (required)

    Your Email (required)

    Your Feedback

    What to do you think of Eventify - Simple Events?

    View Results

    Loading ... Loading ...

    What do you think about the NextGEN Resize Plugin?

    View Results

    Loading ... Loading ...

    What do you think about the site design/UI/IA?

    View Results

    Loading ... Loading ...

      X Close Feedback.