Ask your JavaScript questions! Pay money and get answers fast! (more info)

jQuery question: How can I add a callback to closeDOMWindow JavaScript

  • SOLVED

[[LINK href="http://swip.codylindley.com/DOMWindowDemo.html"]]I'm using the code from this page. [[/LINK]]

If you click one link, then the lightbox pops up. I've got this code to set the action on the link:

if ($('#link_to_create_a_new_country_from_the_region_form')) {
$('#link_to_create_a_new_country_from_the_region_form').openDOMWindow({
eventType:'click',
height:260,
width:350,
loader:1,
loaderImagePath:'/images/animationProcessing.gif',
loaderHeight:16,
loaderWidth:17
});
}



If you click another link, the pop up closes. I've got this code setting the action to click for that link:


if ($('#link_to_close_new_country_form_on_region_form_page')) {
$('#link_to_close_new_country_form_on_region_form_page').closeDOMWindow( {
eventType:'click',
});
}



Only problem is, when you close the pop up, I need a lot of other stuff to happen. I need to update some form inputs.

But how do I get other stuff to happen? I have not been able to figure out how to get other code to trigger when you click that close link.

Does jQuery have an easy way to set several actions on the click? I could write some manual code to do this (I've done stuff like that using a modified version of Simon Willison's [[LINK href="http://simonwillison.net/2004/May/26/addLoadEvent/"]]addLoad script[[/LINK]]) but I worry I will break something in jQuery if I do this.

Answers (3)

2011-01-14

Jarret Minkler answers:

add this option replacing null with your fnc

functionCallOnClose:null,

and you want to remove the training commas in the {} otherwise IE will cry

2011-01-14

Bill Hunt answers:

This doesn't directly answer the question, but that plugin doesn't really seem to be doing things the "jquery way". I'd strongly recommend using the jQuery UI library's dialog function instead, and just attach it to a click through the usual event handlers.

2011-01-15

Eric Hamilton answers:

Add a class to the dom window close links, then do:


$('body').delegate('.my-close-links', 'click', function () {
// do stuff....
// $(this) will be the clicked link.
// You can use .parent( [ selector ] ) to find parent elements of the clicked link.
});


I agree that jQuery UI's built-in .dialog() might be a better solution for you. With it, you can do:


$( ".selector" ).load('someurl').dialog({
buttons: {
"Close": function () {

// Insert whatever you want here...

$(this).dialog("close");
}
}
});