1

I need to close the modal dialog with return a value in a same function

I cannot write code as follow,because when a returning a value, next line never be excuted,

function butOK_OnClick() {
    return "OK";
    window.close();
}

so is this the right way ?

function butOK_OnClick() {
    window.returnvalue = "OK";
    window.close();
}

or what is the best way to do this ?

Madura Harshana
  • 1,299
  • 8
  • 25
  • 40

2 Answers2

2

Assuming you're using window.showModalDialog to open the window (since window.open does not allow for return values), you'd just set the returnValue property of the modal and then set it to a variable in the opener.

Opener window:

var returnedValue = window.showModalDialog(url);

Modal window:

window.returnValue = 'foo';
window.close();
jbabey
  • 45,965
  • 12
  • 71
  • 94
-1

you can use,

$("#modalId", window.top.document).data("cancelled", true);
$("#modalId", window.top.document).data("returnValue", returnVal);