views:

328

answers:

3

I am popping up an HTML page from a Silverlight application using the HtmlPage.PopupWindow() method. I am trying to handle the event of when the popup window is closed from within Silverlight. This is how I am attempting to do this:

 var window = HtmlPage.PopupWindow(new Uri("http://mypopup..."), "popup", options);

 EventHandler<HtmlEventArgs> windowClosed = (sender, e) =>
 {
     // would like to refresh the page when popup is closed...
     HtmlPage.Document.Submit();
 };

 window.AttachEvent("onUnload", windowClosed);

However the event handler never seems to get called. Is this something that is possible or am I missing something?

The Silverlight app and the HTML popup page are on the same domain, however they are actually on different ports. I was thinking that maybe the pages being on different ports would be considered a cross-site restriction and cause the JavaScript to fail.

A: 

Your onUnload event must be defined in the popup window rather than the parent/opener window to detect any actions made on the child window. In the popup you would track actions in that window and send a call to the parent/opener for status updates. With this call you would also pass any values that you need to that window as you can't read the data of the child window from the parent/opener.

If the page is an iframe of the target page, then you would use parent; as in parent.functionname(data);. If the page is a separate window of the target page you would use opener; as in opener.functionname(data);.

JoeFlash
I think you will find that the opener will be null for the same reason that Silverlight could not attach to the onload event. Since the port numbers differ it will be considered a cross-domain script.
AnthonyWJones
A: 

You are correct, the variation in port number is enough to prevent Silverlight from accessing events and content of the popup window.

AnthonyWJones
A: 

You have a very very small bug in event name :) change "onUnload" by "onunload" and try again

Lasha Morgoshia