【发布时间】:2019-02-05 21:30:38
【问题描述】:
我在 IE 11 中遇到问题,当我通过 win1 = window.open(...) 打开一个新窗口时,我无法通过 win1.close() 再次关闭它。
下面,从主窗口注销时,在 OpenWindowWithGet() 下打开的子窗口不会在 IE 11 下关闭。 与 Google Chrome 完美搭配。
[更新]:当我在开发人员工具下的 IE 11 控制台上执行此操作时,我可以使用 window.open(使用分配的变量)打开窗口并使用 window.close() [as var1.close ()]。 只是一些可能有助于分析这种异常的东西。
<html>
<script type="text/javascript">
var win1;
function OpenWindowWithGet(urllink, windowoption, name){
var form = document.createElement("form");
form.method = "GET";
form.action = urllink;
form.target = name;
var input = document.createElement("input");
input.type = "hidden";
input.name = "OAP_Id";
input.value = OAP_Id;
form.appendChild(input);
document.body.appendChild(form);
win1 = window.open(urllink, "Manual", windowoption);
form.submit();}
function OAPLogoutClick(){
disconnectFromNodeServer();
win1.close();
}
MyManual() 函数中 OpenWindowWithGet() 的 HTML 代码 -
<h:panelGrid id="manual" columns="2" cellpadding="2px" cellspacing="0" style="display: inline-block;">
<h:panelGroup>
<a onclick="return myManual();" target="_blank" style="width: 40px; display: inline-block; position: relative; top: 2px; color: #000000">Manual</a>
</h:panelGroup>
<h:outputLabel id="manualSeparator" value=" | " style="color: #000000; display: inline-block;"/>
</h:panelGrid>
OAPLogout() 的 HTML 代码 -
<div class="oapadding5" onclick="hideGroupedInfo();OAPLogoutClick();stopEventPropagation(event);" onmouseover="onRowMouseOver(this);" onmouseout="onRowMouseOut(this);" style="display: #{oASession.m_bShowLogout eq 'true'? '':'none'}">
<h:commandLink id="logoutLink2" styleClass="oatextpaddingleft" style="color: #{oAThemeBean.m_objCurrentThemeInfo.m_strTextFontColor};" value="#{OMNIGEN.LOGOUT}" onclick="return false;">
</h:commandLink>
</div>
相关问题,但提供的解决方案没有帮助。 questions/710756
有什么建议吗?
谢谢。
【问题讨论】:
-
实际的错误信息是什么(如果有的话)?
tab = window.open(...); tab.close()在 IE11 中对我来说很好。 -
未报告具体错误。使用分配的 (window.open()) 变量调用 window.close 时,选项卡不会关闭。控制台日志中也没有错误。当我在开发人员工具下对 IE 11 的控制台执行此操作时,我可以使用 window.open(使用分配的变量)打开窗口并使用 window.close() [as var1.close()] 关闭它。只是一些可能有助于分析这种异常的东西。同样,我也在问题中添加了更新说明。
-
你的代码看起来有点乱,所有这些全局变量。您实际上在哪里初始化
win1和form?我想win1可能会在您的代码中的某个地方重新分配。我鼓励您进行适当的变量初始化并将它们正确地交给函数。 -
win1 被全局初始化,在
-
我很惊讶您的代码完全可以在 Chrome 中运行。在我看来,使用
form.submit();,您正在重新加载页面,从而破坏了您的win1的价值。有点难以判断,因为您的示例不是自包含的。
标签: javascript html internet-explorer-11 window.open