Using a callback function with subModal

no comments Posted by seth Thu, 11 Jan 2007 23:06:00 GMT

I get a lot of questions regarding the use of a callback function with my subModal code. The following is an except from a response I posted over at the subModal google group.

  1. Define the function that’ll be called on the opening page.
  2. Pass the function you’d like to call into ‘showPopWin’.
  3. Assign any return value on the modal page itself, if necessary
  4. Call the hidePopWin function passing true

It might be easier to grok in code, so as an example…

On the subModal opening page

// returnVal can get passed in from the modal page itself...
//....see below for info
function returnRefresh(returnVal) {
  window.document.reload();
}

// Open the modal, passing in the refresh function 
// as a reference NOT a string.
showPopWin('mymodal.html', 500, 500, returnRefresh);

From inside the subModal window

// If you plan to pass a return value assign it
var returnVal = "something";

// When you're ready to close the pop window 
// call this...Passing true makes sure the return 
// function gets called.
window.top.hidePopWin(true); 
Comments

Leave a response

Comments