javascript JS:“被调用者(服务器 [不是服务器应用程序])不可用并消失了。” 访问 window.opener
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3840066/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JS: "The callee (server [not server application]) is not available and disappeared." accessing window.opener
提问by Mike Hofer
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.
在我们的(相当大和旧的)ASP.NET 应用程序中,我们使用了大量加载到框架、iframe 和模式对话框(使用 window.showModalDialog)的页面。我们开始看到上面的错误很多,我似乎无法在任何地方找到一个合理的解释。
Popup Blockers. Nope. We're not running them. Not even the built-in blocker.
Trusted Zone. Nope. The application runs on LocalHost right now, and it's in the trusted sites list.
Stray Cosmic Rays. Possible, but not probable. It's way too consistent.
弹出窗口拦截器。不。我们不是在运行它们。甚至没有内置的拦截器。
可信区。不。该应用程序现在在 LocalHost 上运行,并且位于受信任的站点列表中。
杂散宇宙射线。有可能,但不大可能。太连贯了。
I dideventually find the error message buried on Microsoft's site in some dusty tomeabout 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."
我也终于找到埋在微软的网站上的错误消息,一些尘封的大部头有关检索自动化错误消息的信息。在其中,他们谈论的是 Excel,他们说:“在这个例子中,Microsoft Excel 是服务器应用程序。一旦工作簿对象被销毁(或关闭),引用它就会产生错误。”
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.
- 页面 A 是主页面。
- PageA 在一个框架中显示 PageB。PageB 是一个工具栏。
- PageA 在另一个框架中显示 PageC。这就是内容。
- PageC 在非模态对话框中显示 PageD。
- 由于我不知道的原因,PageD 想要修改 PageB 中的控件。它试图使用 window.opener 来做到这一点,但失败了。
If someone could enlighten me as to why this is the case (the code works in FF), I'd appreciate it.
如果有人能启发我解释为什么会这样(代码在 FF 中有效),我将不胜感激。
采纳答案by Mike Hofer
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.
对于使用 window.showModalDialog 打开的窗口,window.opener 方法返回 null,而不是对打开窗口的引用。要获得对打开窗口的引用,您必须将其作为对话框参数传递。
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.
目前我不清楚这是否是有意的行为;这显然是无证行为。此外,根据 MSDN,window.opener 仅对加载到框架和 iframe 中的页面有效。
回答by Johnny Oshika
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().
尽管我的回答并不直接适用于这个特定问题,但如果您在弹出窗口和开启程序窗口之间进行通信时遇到此错误(被调用方(服务器 [不是服务器应用程序])不可用并消失了;) ,这是因为弹出窗口创建了一个对象,然后将其传递给 opener 窗口。当弹出窗口关闭时,Internet Explorer 会删除由弹出窗口创建的所有对象。并且由于对象是通过引用传递的,因此打开器窗口引用的对象现在已经消失了。一个简单的解决方法是通过使用 JSON.stringify 将对象转换为 JSON 字符串来按值传递。然后,您可以使用 JSON.parse() 将字符串转换回 window.opener 中的对象。
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.
使用这种方法,opener 窗口不再引用在弹出窗口中创建的对象,因此在弹出窗口关闭后,opener 窗口中的对象将继续存在。
回答by krul
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");
我在以下场景中收到了完全相同的错误消息:窗口 A 弹出风 B,用户搜索某些内容,风 B 调用风 A 并传递一些参数。在风 A 上调用的方法假设在完成它正在做的事情后关闭弹出风 B。我将参数作为对象传递: p ={a: 1, b:"c"} 在我重写代码以分别传递每个参数后,错误消失了。调用方法(1,“c”);
Hope that helps somebody...
希望能帮助某人...
回答by greg
you can get this error in excel
你可以在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.
这里 frmParm 是一个模块级变量。单击“确定”按钮,我打算将 .HIDE() 表单隐藏起来,以便用户的选择具有粘性。如果用户单击控制框 X 并关闭表单,那么您基本上让 frmParm 指向不再存在的内容。
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.
我意识到这不完全是被问到的问题,但它是帖子中多次提到的相关 excel 问题的具体示例。

