Close the parent window when opening popup window

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rkyakkala
    New Member
    • Oct 2010
    • 11

    Close the parent window when opening popup window

    Hi,
    i am creating a popupwindow example.After entering the details i want to close the parent window(details. html)as it is moving to new window.could anybody suggest how can i do both task at a time i.e., closing the parent window and opening the new window.
    Thanks in advance.
    Following is my code:
    Popup.html
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
    <A HREF="javascript:void(0)"onclick="window.open('details.html','details','dependent=no,width=300,height=200,menubar=yes,status=yes,location=yes,toolbar=yes,scrollbars=yes')">Open a new window</A>
    
    </body>
    </html>
    details.html
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
    <script>
    function getURL(sClassName,sInstance){
    
    alert("in getURL:::"+sClassName+"::"+sInstance);
    window.open();
    
    }
    </script>
    <form method="post">
    <table border="0" align="center" bgcolor="999999">
    <tr>
    <td>choose from the list</td>
    <td>
    <select name="classname">
    <option value="Router">Router</option>
    <option value="Session">Session</option>
    <option value="IP">IP</option>
    </select>
    </td>
    </tr>
    <tr>
    <td>Enter Host Name</td>
    <td><input type="textfield" name="instance"/></td>
    </tr>
    <tr>
    <td height="38" colspan="2">            <div align="center">
    <input type="submit" name="submit" value="click" onclick="getURL(classname.value,instance.value);"/>
    </td>
    </tr>
    </table>
    </form>
    
    </body>
    </html>
  • rkyakkala
    New Member
    • Oct 2010
    • 11

    #2
    closing the parent window in html

    Hi,
    Here there are two htmls(Details.h tml and popup.html).whe never popup.html loaded details.html window need to be closed.but here both windows are closing at a time.could any body suggest what i need to do to close only parent window?
    thanks in advance.
    Code:
    //DETAILS.HTML
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
    <A HREF="javascript:void(0)" onclick="window.open('details.html','details','dependent=no,width=300,height=200,menubar=yes,status=yes,location=yes,toolbar=yes,scrollbars=yes')">Open a new window</A>
    
    </body>
    </html>
    Code:
    //Popup.html
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
    <script>
    function getURL(sClassName,sInstance){
    
    alert("in getURL:::"+sClassName+"::"+sInstance);
    
    mywindow=window.open("http://www.google.com");
    
    }
    function parentClose(){
    alert("in parentclose");
    javascript:window.parent.close();
    }
    </script>
    <form name="detailswin" method="post" onsubmit="parentClose()">
    <table border="0" align="center" bgcolor="999999">
    <tr>
    <td>choose from the list</td>
    <td>
    <select name="classname">
    <option value="Router">Router</option>
    <option value="Session">Session</option>
    <option value="IP">IP</option>
    </select>
    </td>
    </tr>
    <tr>
    <td>Enter Host Name</td>
    <td><input type="textfield" name="instance"/></td>
    </tr>
    <tr>
    <td height="38" colspan="2">            <div align="center">
    <input type="submit" name="submit" value="click" onclick="getURL(classname.value,instance.value)"/>
    </td>
    </tr>
    </table>
    </form>
    
    </body>
    </html>

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      It wouldn't be a good idea to do that. It doesn't really make sense to.

      Anyway, if you insist, the easiest way would be to use the child window to close the parent window on page load:
      Code:
      window.opener.close();

      Comment

      Working...