Web Analytics Made Easy -
StatCounter Closing parent window? - CodingForum

Announcement

Collapse
No announcement yet.

Closing parent window?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Closing parent window?

    Is it possible for the window to close the window that created it?
    I have a form that creates a 2nd window. After a certain amount of time I want this 2nd window to close the first one.
    ?

  • #2
    to make a refernece to the windows parent (not to be mistaken with frames paretn) you use
    window.opener.close()

    using "window.opener" is equal to the "window" object of the first window
    photoshop too expensive? use the GIMP! www.gimp.org

    Comment


    • #3
      Just keep in mind that if the parent window wasn't called via window.open then you're going to get the security popup message that confirms you want to close the window.

      There really isn't anything you can do about that window either.

      Comment


      • #4
        Yes, there is - you can close a window like this without confirmation message:

        <object id=closeWin type="application/x-oleobject" classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">
        <param name="Command" value="Close">
        </object>
        <a href="javascript: void(0)" onclick="closeWin.Click()">Close this window!</a>

        Saludo, piz
        www.united-scripts.com
        www.codebattles.org

        Comment


        • #5
          in the parent window:

          window.open("URL","target","features");
          window.opener = top;
          setTimeout("window.close()",1000);
          Last edited by glenngv; Nov 22, 2002, 05:53 AM.
          Glenn
          vBulletin Mods That Rock!

          Comment


          • #6
            Originally posted by piz
            Yes, there is - you can close a window like this without confirmation message:

            <object id=closeWin type="application/x-oleobject" classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">
            <param name="Command" value="Close">
            </object>
            <a href="javascript: void(0)" onclick="closeWin.Click()">Close this window!</a>

            Saludo, piz
            Piz, it works a treat for an onClick, however; I can't work out how one would be able to alter the code so that it closes the window "immediately after" you use javascript to created a child window.
            If I put the Object into the header and use an onload=function it reports the "closeWin" isn't defined.
            How else would you do it?

            Comment


            • #7
              use the code I posted in my previous post (which I edited to make some corrections ), it's from http://aspalliance.com/peterbrunone/impossible.asp
              Last edited by glenngv; Nov 22, 2002, 05:54 AM.
              Glenn
              vBulletin Mods That Rock!

              Comment


              • #8
                Glenngv...I tried this below: but it still gave the security dialog, I don't know where you previous post is because I found this one from a "search"

                <SCRIPT LANGUAGE="JavaScript">
                window.open("WhereAmI.asp","newWindow","height=520,width=730,toolbars=no,scrollbars=yes,resizable=ye s");
                window.opener = top;
                window.close();
                </SCRIPT>
                Last edited by skeatt; Nov 22, 2002, 06:35 AM.

                Comment


                • #9
                  what browser are you using? Check the aspalliance link that I posted. It listed what browsers that work with this code.
                  Glenn
                  vBulletin Mods That Rock!

                  Comment


                  • #10
                    Here's my code:


                    <html>
                    <head>
                    <script type="text/javascript">
                    function init() {
                    window.open('mywin.htm','myWin','height=400,width=400');
                    setTimeout("window.focus();closes.Click();",10000);}
                    </script>

                    </head>
                    <body onload="init()">
                    <object id="closes" type="application/x-oleobject"
                    classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">
                    <param name="Command" value="Close">
                    </object>

                    </body>
                    </html>



                    Place this code on the parent page. Don't forget the onLoad event.

                    Text in bold is editable.

                    Assigning the timeout to 10000 will close it after 10 seconds - adjust as needed.

                    Hope that helps!
                    Quيet Storm Designs ~ Art is not what you see, but what you make others see.
                    · the Storms· || ·Ultraviolent Winter· || ·Was Einstein Wrong?· || ·It´s About Time!·

                    Comment


                    • #11
                      I've cracked it in a clean way....that also allows netscape to close while using this snippet.
                      The trick is to call it after every thing has loaded and defined the classID, similar to your timing one but straight away, This part in the body triggers things....
                      <script language=Javascript>closeOpener()</script>
                      I noticed if you use the onload the <object id=... isn't defined.

                      Here is the full script......


                      <html>
                      <head>
                      <script type="text/javascript">
                      <!-- hide code
                      function closeOpener() {
                      newWin = window.open('url','mainWin','width=780,height=550,toolbar=yes,directories=no,status=no,scrollbars=no ,resizable=yes,menubar=no');
                      window.focus();
                      if (navigator.appName == "Microsoft Internet Explorer") {
                      closeWindowOpener.Click(); // use this for IE5
                      }
                      else {
                      self.close(); // used this for Netscape
                      }}
                      // -->
                      </script>
                      </head>
                      <body bgcolor="#207377">
                      <object id=closeWindowOpener classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11" type="application/x-oleobject">
                      <param name="Command" value="Close">
                      </object>
                      <script language=Javascript>closeOpener()</script>

                      </body>
                      </html>

                      Comment

                      Working...
                      X