2014-11-17 78 views
2

我的查詢是,註銷後關閉所有子窗口(如果打開)。 我從不同的jsps創建子窗口&我想從Search.jsp關閉它。 Search.jsp具有創建,註銷等按鈕。如何在Javascript中通過名稱獲取窗口對象?

我search.jsp的是 -

<% 
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>&nbsp;&nbsp;Name</td> 
        <td><input type="text" name="name" value="*" required /></td> 
        <td>&nbsp;&nbsp;Description</td> 
        <td><input type="text" name="description" value="*" required /></td> 
        <td></td><td></td> 
        <td><input type="submit" value="Search" /></td> 

       <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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> 

這裏,如果我在註銷按鈕點擊,那麼它必須關閉所有打開的子窗口。 我從不同的jsp創建的childs窗口。 例如,從search.jsp的,我打開屬性頁即,

<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,我打開編輯JSP即,

<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> &nbsp;&nbsp;</h5> 

&同樣。 據我所知,我可以實現這一點,如果我從相同的jsp即創建子窗口即。僅限Search.jsp。

我的讀數 -

How to close all the child pages on LogOut

How to Close multiple child windows from a parent window

這再次說明只有在窗口引用是唯一的JSP。 所以請建議我,我如何關閉所有子窗口,從另一個jsp(Search.jsp)創建不同jsp的 ?

任何建議或任何其他方式來實現這一目標,將對我非常有幫助。

在此先感謝。

+0

應刪除Java標記。 Java與JavaScript無關。 –

+0

@HowardRenollet - 你是對的,一定是星期一布魯斯:-)通常我只是留下評論...(Downvote and comment undone) –

+0

@GyroGearless - 謝謝。我的評論也被刪除了:)祝你有一天好好休息! –

回答

0

由於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"); 
} 
+0

我明白了。如果您僅從同一個jsp創建子窗口,它將起作用。但是,如何回答開放窗口引用從不同的jsp的問題? – user3916928

相關問題