August 30, 2001 - Using the Caller's Method from within the Dialog Box | WebReference

August 30, 2001 - Using the Caller's Method from within the Dialog Box

Yehuda Shiran August 30, 2001
Using the Caller's Method from within the Dialog Box
Tips: August 2001

Yehuda Shiran, Ph.D.
Doc JavaScript

When you call a dialog box with either showModalDialog() or showModelessDialog(), you can use the second parameter to pass information from the caller to the callee and vice versa. Suppose you have a function definition in the caller, and you want to call the function from within the callee. You know that all functions are methods of the window object. You need to pass the window object to the callee, and then have the callee call the particular method.

Here is how you call the dialog box:

showModelessDialog("010828b.html",window,
   "status:false;dialogWidth:300px;dialogHeight:150px");
Notice the window object in the second position. The callee reads in the second parameter into the dialogArguments variable. It can be a scalar, an array, an object, etc. In the following example the callee first assigns dialogArguments to the callerWindowObj, and then calls the update() method of this object:

  var callerWindowObj = dialogArguments;
  callerWindowObj.sColor = oEnterColor.value;
  callerWindowObj.update(); 
The function update() is defined in the caller as:

function update()
{
  oColor.innerText = sColor;
}
For more on modal and modeless dialog boxes, go to Column 90, Modal and Modeless Dialog Boxes.