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();
}

2 comments:

  1. great suggesstion reajendran!!!!!!i was looking for this solution for days!!!!now please tell me how can i get the value of modal window variable in parentwindow

    ReplyDelete
  2. Please see that in parent window I have declared a variable called
    "retval" value will be populated in this variable on close of modal window.

    ReplyDelete