开发者

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 M开发者_如何学Pythonicrosoft'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.


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.


I should have updated this question earlier, and I apologize for the delay. I've learned a bit since I posted it, and here's what I've learned.

For windows opened with window.showModalDialog, the window.opener method returns null, rather than a reference to the opening window. To get a reference to the opening window, you have to pass it as a dialog argument.

It's unclear to me at this point whether or not this is intended behavior; it's apparently undocumented behavior. Further, according to MSDN, window.opener is only valid for pages loaded into frames and iframes.


I had the exact same error message in following scenario: window A pop ups wind B, user search something and wind B calls wind A passing some parameter. Method called on wind A suppose to close popup wind B after it finish doing what it's doing. I was passing parameter as object: p ={a: 1, b:"c"} after I rewrite the code to pass each parameter separately error disappeared. callingMethod(1,"c");

Hope that helps somebody...


you can get this error in excel

Sub LoadParameterForm()

If frmParm Is Nothing Then
    Set frmParm = New frm_setParameters
End If

frmParm.Show
end sub 

Here frmParm is a module level variable. Clicking the OK button, I intend to .HIDE() the form so the user's choices are sticky. If the user clicks on the control box X and closes the form, then you essentially have frmParm pointing at something that no longer exists.

I have not found a way to test for the condition, I trap for the error, set the form to nothing and try again.

I realize this is not exactly the question being asked, but it is a concrete example of the related excel issue mentioned several times in the posts.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜