Jan 11
2007

Using a callback function with subModal

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); 
Written by Seth B

As Principal of Subimage LLC, Seth spends most of his days improving Cashboard. Occasionally he finds time to write about music, design, startups, and technology.

Tagged: javascript, submodal