如何在Javascript中按名称获取窗口对象?
我的问题是,在注销后关闭所有子窗口(如果打开)。 我正在从不同的jsp创建子窗口&我想从Search.jsp关闭它。 jsp有创建、注销等按钮 我的Search.jsp是-如何在Javascript中按名称获取窗口对象?,javascript,jquery,jsp,Javascript,Jquery,Jsp,我的问题是,在注销后关闭所有子窗口(如果打开)。 我正在从不同的jsp创建子窗口&我想从Search.jsp关闭它。 jsp有创建、注销等按钮 我的Search.jsp是- <% String sessionstart = (String)session.getAttribute("sessionstart"); if(sessionstart != null) { %> <body> <div align="center" >
<%
String sessionstart = (String)session.getAttribute("sessionstart");
if(sessionstart != null)
{
%>
<body>
<div align="center" > <img src="images/Headerimage.png" alt=""> </img></div>
<div id = "leftmargin" >
<form action="Search" method="post">
<table cellspacing="10" cellpadding="10">
<tr >
<td >Type</td>
<td><input type="text" name="type" value="*" required /></td>
<td> Name</td>
<td><input type="text" name="name" value="*" required /></td>
<td> Description</td>
<td><input type="text" name="description" value="*" required /></td>
<td></td><td></td>
<td><input type="submit" value="Search" /></td>
<td>
</td>
<td><h5> <input type="button" value="Create" onclick="Create();" /></h5> </td>
<td> <h5> <input type="button" value="Logout" onclick="Logout(); " /> </h5> </td>
</tr>
</table>
</form>
</div>
<%
if (sessionset != null) {
%>
<div align="center" style="margin-top: 15%">
<img src="images/DocumentManagementSplash.png" alt=""> </img>
</div>
<%
}
%>
</body>
<%
}
else
{
%>
<script>
window.location.replace("ietmLoginDialog.jsp");
</script>
<%
}
%>
<script type="text/javascript">
function Create() {
window.open("ltIEnterCreatePartFileUpload.jsp?", "CreatePart",
"height=140,width=350");
}
function Logout() {
var w = document.getElementsByName("mywin");
alert("w closed :: "+ w.closed);
alert("w name :: "+ w.name);
alert("w open:: "+ w.open);
if(w.name == "mywin"){
w.close();
}
window.open("ietmLoginDialog.jsp", '_self', "location=yes");
}
</script>
类型
名称
描述
replace(“ietmLoginDialog.jsp”);
函数Create(){
打开(“ltIEnterCreatePartFileUpload.jsp?”,“CreatePart”,
“高度=140,宽度=350”);
}
函数注销(){
var w=document.getElementsByName(“mywin”);
警报(“w关闭::”+w关闭);
警报(“w名称::”+w名称);
警报(“w打开::”+w打开);
如果(w.name==“mywin”){
w、 close();
}
open(“ietmLoginDialog.jsp”,“self”,“location=yes”);
}
在这里,如果我单击注销按钮,那么它必须关闭所有打开的子窗口。
我从不同的jsp创建的儿童窗口。
例如,在Search.jsp中,我打开属性页ie
<td style="width: 170px;" ><a
href="ltSearchDocProperties.jsp?idvalue=<%=strObjectId%>"
onclick="window.open(this.href, 'mywin',
'left=20,top=20,width=900,height=725'); return false;"><%=strName%></a></td>
在Property.jsp中,我打开edit jsp ie
<h5 align="right">
<a href="ltSearchDocEdit.jsp?idvalue=<%=strObjectId%>" onclick="window.open(this.href, 'mywiirn','width=900,height=615,resizable=false'); return false;">Edit</a> </h5>
&同样地。
据我所知,如果我仅从同一个jsp ie.Search.jsp创建子窗口,就可以实现这一点
我的读数是-
同样,这只描述了窗口引用仅在jsp中的情况。
所以请建议我,如何关闭所有子窗口,从不同的jsp创建
来自另一个jsp(Search.jsp)
任何建议或任何其他方式来实现这一点,将非常有助于我
提前感谢。由于window.open()
返回对所创建窗口的引用,您可以将它们存储在变量中,并在注销时关闭它们:
var windowsToCloseOnLogout = [];
function create() {
windowsToCloseOnLogout.push(window.open("ltIEnterCreatePartFileUpload.jsp?", "CreatePart", "height=140,width=350"));
}
function logout() {
for (var i = 0, windowNb = windowsToCloseOnLogout.length; i < windowNb ; i++) {
windowsToCloseOnLogout[i].close();
}
window.open("ietmLoginDialog.jsp", '_self', "location=yes");
}
var windowsToCloseOnLogout=[];
函数create(){
windowsToCloseOnLogout.push(window.open(“ltIEnterCreatePartFileUpload.jsp?”,“CreatePart”,“高度=140,宽度=350”);
}
函数注销(){
对于(变量i=0,windowNb=windowsToCloseOnLogout.length;i
您应该删除Java标记。Java与javascript无关。@HowardRenollet-你说得对,一定是星期一的布鲁斯:-)通常我只是留下一条评论。。。(否决票和未完成的评论)@gyroless-谢谢。我的评论也被删除:)好好休息一天吧!我得到了它。如果您仅从同一个jsp创建子窗口,那么它将起作用。但是,如何从不同的jsp返回开放窗口引用呢?