Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JS: "The callee (server [not server application]) is not available and disappeared." accessing window.opener

In our (quite large and old) ASP.NET application we use a lot of pages loaded into frames, iframes, and modal dialogs (using window.showModalDialog). We are starting to see the error above quite a bit, and I can't seem to find a single rational explanation for it anywhere.

  1. Popup Blockers. Nope. We're not running them. Not even the built-in blocker.

  2. Trusted Zone. Nope. The application runs on LocalHost right now, and it's in the trusted sites list.

  3. Stray Cosmic Rays. Possible, but not probable. It's way too consistent.

I did eventually find the error message buried on Microsoft's site in some dusty tome about retrieving automation error message information. In it, they were talking about Excel, and they said: "In this example, Microsoft Excel is the server application. Referencing a workbook object once it is destroyed (or closed) generates the error."

That is probably as close as I've ever come to an explanation for the cause of the error, without a real, concrete explanation. Someone tried to use something after their reference to it was disposed of. Oddly, you can still see the windows on the screen. Curiously, however, this smacks suspiciously to me of the accepted answer to this.

So here's what happens.

  • Page A is the main page.
  • PageA displays PageB in a frame. PageB is a toolbar.
  • PageA displays PageC in another frame. That's the content.
  • PageC displays PageD in a nonmodal dialog.
  • PageD, for reasons unknown to me, wants to modify the controls in PageB. It's trying to use window.opener to do that, and failing horribly.

If someone could enlighten me as to why this is the case (the code works in FF), I'd appreciate it.

like image 563
Mike Hofer Avatar asked Oct 01 '10 14:10

Mike Hofer


1 Answers

Although my answer isn't directly applicable to this particular question, if you're getting this error (The callee (server [not server application]) is not available and disappeared;) when communicating between a pop-up window and the opener window, it's because the pop-up window created an object which it then passed to the opener window. When the pop-up window is closed, Internet Explorer kills all objects created by the pop-up window. And since the object is passed by reference, the object to which the opener window references is now gone. An easy workaround is to pass by value by converting the object to a JSON string using JSON.stringify. You can then convert the string back to an object in window.opener using JSON.parse().

Example:

Pop-up Window:

window.opener.callback(JSON.stringify({
    id: 1,
    name: "foo"
}));

Opener Window:

window.callback = function (response) {
    var foo = JSON.parse(response);
};

Using this approach, the opener window is no longer referencing the object that was created in the pop-up window, so the object in the opener window will survive after the pop-up is closed.

like image 162
Johnny Oshika Avatar answered Sep 28 '22 11:09

Johnny Oshika