Pages

Wednesday, July 20, 2011

Accessing parent window function from modal window

if you create a modal dialog window and try to access any function from parent window, well its not possible, any browser will not allow you to access parent window functions unless it is a normal window. so the alternate possible solution is as below
modal window can return a value to parent window's calling function, so based on its value you can either change parent window variables or call any function. It is only possible when your child modal window is closing.
here it is how.

// parent window JS
retval= window.showModalDialog( "mynewpage.jsp", myArguments, "dialogHeight: 100px; dialogWidth: 400px; edge: Raised; center: Yes; resizable: Yes; status:Yes ; scroll:Yes;");
resetTimer(retval);

// in child window JS i.e. mynewpage.jsp
function closeMe()
{
window.returnValue="60";
window.close();
}