Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Returning Values from Modal Dialog Box

 
Animesh Saxena
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am creating a modal dialog box. Everything in the dialog box is modal. I want to return some value from this modal dialog box to the parent window. The problem is it is always returning "UNDEFINED"

If instead of dynamic values i use window.showModalDialog("somepage.htm")
it returns values perfectly from the javascript of the page "somepage.htm".

Since I am forming this html dynamically it is not showing anything when i try to get the value of window.returnValue.

Has anybody come across a similar issue please lemme know?
CANCEL </BUTTON></TD>" +" </TR>"
+" </TABLE>";

var pg="javascript:'<html><head>" + titl + js + "</head><body>"+bdy+"</body></html>'";

var MyArgs = window.showModalDialog(pg,window.self,WinSettings);
//var MyArgs = window.open(pg,'','');

alert(MyArgs);

}

</script>
</HEAD>
</HTML>
[/CODE]


[/CODE]
 
Jon Hanlon
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the modal window, the incoming parameters are found in window.dialogArguments
and the return value (result) should be placed in window.returnValue

Back in the main page, the return value (result) is found by
var result = window.showModalDialog(sURL,vArgs,sFeats);
 
Pavan Keely
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Animesh,

This is a security restriction on Modal Dialog boxes. Because the main page is accessed using "http" or "file" protocol, where as the modal dialog will have "javascript" pseudo protocol. So, if the protocols are different then they can not communicate. It's the same rule for domains. If dialog box html source is not from the same domain as main page then access then they will not communicate. I think that's the very reason why the return value is always undefined and when you try to access using HTML from the external HTML page, you are able to get the return value.

Hope you know that window.showModalDialog is not supported by Mozilla Firefox or Mozilla based browsers in general.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic