使用JavaScript window.open()发生奇怪的IE7行为

时间:2022-10-22 15:30:31

The following code was known to be working three weeks ago. In the interim we have installed IE 7 and a bunch of security patches. The ultimate question will be, does anyone know how to restore the old behavior?

以下代码已知在三周前正在运行。在此期间,我们安装了IE 7和一堆安全补丁。最终的问题是,有谁知道如何恢复旧的行为?

Scenario

We have the following JavaScript code in web page 1 (let's call it foo.aspx), that is invoked on a button click:

我们在网页1中有以下JavaScript代码(我们称之为foo.aspx),它是在按钮点击时调用的:

window.open("http://Foo/App2/bar.aspx, "_blank", "titlebar,status,width=650,height=600");

The second web page (bar.aspx) is then supposed to open on top of foo.aspx. The user does some stuff, and when they click a button bar.aspx writes some values from bar.aspx back into fields on foo.aspx using JavaScript via window.opener.document, addressing each element individually and modifying its innerText. Then the user closes bar.aspx and there's foo.aspx where they left it, except now it has the values from bar.aspx in certain fields, and the user goes happily on their way using foo.aspx. This has been working for over two years.

然后应该在foo.aspx之上打开第二个网页(bar.aspx)。用户执行一些操作,当他们单击按钮bar.aspx时,使用JavaScript通过window.opener.document将bar.aspx中的一些值写回到foo.aspx上的字段中,单独寻址每个元素并修改其innerText。然后用户关闭了bar.aspx并且foo.aspx离开了它,除非现在它在某些字段中具有bar.aspx的值,并且用户在使用foo.aspx时很开心。这已经工作了两年多。

During the last two weeks we've applied a bunch of security patches and upgraded to IE 7. Now the behavior is this:

在过去的两周里,我们已经应用了一堆安全补丁并升级到IE 7.现在的行为是这样的:

  1. If I am testing and simply navigate to foo.aspx directly, then upon clicking the button bar.aspx opens and then suddenly the focus switches back to foo.aspx with a popup dialog with "The webpage you are viewing is trying to close the window. Do you want to close this window? " If I choose "No", then foo.aspx stays alive, I have to Alt-Tab to get back to bar.aspx, and after that everything works as before. However, this is going to be a pain for the users. Note: NOWHERE IN foo.aspx NOR bar.aspx IS THERE A CALL TO THE close() METHOD!!! So I don't understand why the popup says what it says.

    如果我正在测试并直接导航到foo.aspx,那么在点击按钮bar.aspx后会打开,然后突然焦点切换回foo.aspx并弹出一个对话框,“您正在查看的网页正在尝试关闭窗口你想关闭这个窗口吗?“如果我选择”No“,那么foo.aspx会保持活着状态,我必须让Alt-Tab返回bar.aspx,之后一切都和以前一样。然而,这对用户来说将是一种痛苦。注意:NOWHERE在foo.aspx NOR bar.aspx是一个呼叫关闭()方法!!!所以我不明白为什么弹出窗口会说出它的内容。

  2. If I access foo.aspx via the application, which means it has been opened programmatically and not explicitly by the user, then bar.aspx opens and you can see foo.aspx disappear (close) behind it. Then bar.aspx gets JavaScript errors because the window.opener is no longer available.

    如果我通过应用程序访问foo.aspx,这意味着它已经以编程方式打开而不是由用户显式打开,那么bar.aspx会打开,你可以看到foo.aspx在它后面消失(关闭)。然后bar.aspx获取JavaScript错误,因为window.opener不再可用。

Secenario #1 is non-optimal but at least would be a valid work around (if somewhat of a user training issue to train them to hit "No" and then Alt-Tab, where before none of this was happening. Scenario #2 is non-optimal in the extreme, given that the whole purpose of bar.aspx is to write those values back to foo.aspx.

场景#1不是最优的,但至少是一个有效的解决方法(如果有一些用户训练问题,训练他们点击“否”,然后是Alt-Tab,之前没有发生这种情况。场景#2是鉴于bar.aspx的整个目的是将这些值写回foo.aspx,在极端情况下是非最优的。

Other things to note

其他注意事项

  1. Now that we've installed IE 7 and the subsequent Active Directory policy changes, the behavior is happening as described even on IE 6.

    现在我们已经安装了IE 7并且随后的Active Directory策略发生了变化,即使在IE 6上也会发生这种情况。

  2. Both foo.aspx and bar.aspx run on the web server, on the same web site, but in different virtual directories. These are internal application accessible only from inside our network by authenticated users.

    foo.aspx和bar.aspx都在Web服务器上运行,位于同一网站上,但位于不同的虚拟目录中。这些内部应用程序只能由经过身份验证的用户从我们的网络内部访问

  3. Having the server in Intranet zone (where it normally is) or in Trusted Sites makes no difference. I can see no settings in either Zone nor in Advanced Settings that would apply to this behavior, and both the Intranet and Trusted Sites zones are set to be extremely liberal in their policies, especially around script behavior.

    将服务器置于Intranet区域(通常位于其中)或可信站点中没有任何区别。我可以在区域和高级设置中看不到适用于此行为的设置,并且Intranet和可信站点区域在其策略中都设置得非常宽松,特别是在脚本行为方面。

  4. I can make any changes I need to in bar.aspx and its client-side scripts, but am limited to only being able to change the button click JavaScript code in foo.aspx (that page is supplied by a vendor, whereas bar.aspx is internally developed).

    我可以在bar.aspx及其客户端脚本中进行任何我需要的更改,但仅限于能够更改foo.aspx中的按钮单击JavaScript代码(该页面由供应商提供,而bar.aspx是内部开发的)。

  5. I reiterate that other than the updates through window.opener.document, foo.aspx is not touched by bar.aspx, and certainly there is no attempt to invoke close() on it.

    我重申除了通过window.opener.document进行的更新之外,bar.aspx没有触及foo.aspx,当然也没有尝试在它上面调用close()。

So, the question remains what in IE 7, or more likely in a security patch, would have broken this? We have a sister shop that is running the same code on IE 7 and they have not reported this issue. So it seems like it has to be something environmental, and right now I keep thinking it must be a patch that got applied. I would take a KB article, IE setting, registry hack, JavaScript change or anything else to fix this.

那么,问题仍然存在于IE 7中,或者更有可能在安全补丁中,会破坏这一点?我们有一个姐妹店在IE 7上运行相同的代码,他们没有报告此问题。所以它似乎必须是环保的东西,现在我一直认为它必须是一个应用的补丁。我会采取知识库文章,IE设置,注册表黑客,JavaScript更改或其他任何来解决这个问题。

Thanks for any and all suggestions.

感谢您的任何建议。

4 个解决方案

#1


it might be a typo but there's a missing " after the bar.aspx in the sample code.

它可能是一个拼写错误但是在示例代码中的bar.aspx之后缺少了“。

#2


Opening a window programatically and setting the name to _blank, why are you doing that? I'm not saying that has anything to do with your issue, but it's probably not a good idea.

以编程方式打开一个窗口并将名称设置为_blank,为什么要这样做?我不是说这与你的问题有任何关系,但这可能不是一个好主意。

#3


It is odd, first thing I would do is fix up a couple strange things in the code so far.

这很奇怪,我要做的第一件事就是在代码中找到几个奇怪的东西到目前为止。

Use an absolute path such as "/App2/bar.aspx" without the protocol or server name since the apps are on the same server.

使用绝对路径,例如“/App2/bar.aspx”,没有协议或服务器名称,因为应用程序位于同一服务器上。

You can't actually control the titlebar or status bar outside the intranet zone so remove those values from the options list.

您实际上无法控制Intranet区域外的标题栏或状态栏,因此请从选项列表中删除这些值。

#4


Is the pop up blocker closing the pop up window?

弹出窗口阻止程序会关闭弹出窗口吗?

#1


it might be a typo but there's a missing " after the bar.aspx in the sample code.

它可能是一个拼写错误但是在示例代码中的bar.aspx之后缺少了“。

#2


Opening a window programatically and setting the name to _blank, why are you doing that? I'm not saying that has anything to do with your issue, but it's probably not a good idea.

以编程方式打开一个窗口并将名称设置为_blank,为什么要这样做?我不是说这与你的问题有任何关系,但这可能不是一个好主意。

#3


It is odd, first thing I would do is fix up a couple strange things in the code so far.

这很奇怪,我要做的第一件事就是在代码中找到几个奇怪的东西到目前为止。

Use an absolute path such as "/App2/bar.aspx" without the protocol or server name since the apps are on the same server.

使用绝对路径,例如“/App2/bar.aspx”,没有协议或服务器名称,因为应用程序位于同一服务器上。

You can't actually control the titlebar or status bar outside the intranet zone so remove those values from the options list.

您实际上无法控制Intranet区域外的标题栏或状态栏,因此请从选项列表中删除这些值。

#4


Is the pop up blocker closing the pop up window?

弹出窗口阻止程序会关闭弹出窗口吗?