open a new window, then close the old one

Discussion in 'Javascript' started by Navillus, May 17, 2006.

  1. Navillus

    Navillus Guest

    Hi all,

    Trying to make a script function that opens a new window with a new
    location, and then closes the old window. My function looks like this:

    <script language="javascript">

    function deletecook()
    {
    new_win = window.open('http://www.blahblahblah.com/')
    window.close()
    }
    </script>

    But it doesn't close any windows, not even the one it just opened. Any
    takers?
     
    Navillus, May 17, 2006
    #1
    1. Advertising

  2. Navillus

    Navillus Guest

    Navillus wrote:
    > Hi all,
    >
    > Trying to make a script function that opens a new window with a new
    > location, and then closes the old window. My function looks like this:
    >
    > <script language="javascript">
    >
    > function deletecook()
    > {
    > new_win = window.open('http://www.blahblahblah.com/')
    > window.close()
    > }
    > </script>
    >
    > But it doesn't close any windows, not even the one it just opened. Any
    > takers?


    Sort of fixed it, because i was in a windowed page, so the fix was
    top.window.close()
    But it gives this buggy warning message asking if youre sure you want
    to close the window... don't suppose there is a way to supress that?
     
    Navillus, May 17, 2006
    #2
    1. Advertising

  3. Navillus

    ASM Guest

    Navillus a écrit :
    > Hi all,
    >
    > Trying to make a script function that opens a new window with a new
    > location, and then closes the old window. My function looks like this:
    >
    > <script language="javascript">
    >
    > function deletecook()
    > {
    > new_win = window.open('http://www.blahblahblah.com/')
    > window.close()
    > }
    > </script>
    >
    > But it doesn't close any windows, not even the one it just opened. Any
    > takers?
    >


    You can't close a window if it hasn't been opened by javascript
    truc = window.open('page.htm');

    in this context, 'page.htm' will be abble to close itself.

    if it is
    you could try :

    function delecook() {
    w = window.open('page.htm');
    w.onload = self.close();
    }

    --
    Stephane Moriaux et son [moins] vieux Mac
     
    ASM, May 17, 2006
    #3
  4. Navillus

    Randy Webb Guest

    Navillus said the following on 5/16/2006 9:18 PM:
    > Navillus wrote:
    >> Hi all,
    >>
    >> Trying to make a script function that opens a new window with a new
    >> location, and then closes the old window. My function looks like this:
    >>
    >> <script language="javascript">
    >>
    >> function deletecook()
    >> {
    >> new_win = window.open('http://www.blahblahblah.com/')


    Ever tested code such as that with the Symantec Popup Blocking Software?
    Your code will not do what you think it should.

    >> window.close()
    >> }
    >> </script>
    >>
    >> But it doesn't close any windows, not even the one it just opened. Any
    >> takers?

    >
    > Sort of fixed it, because i was in a windowed page, so the fix was
    > top.window.close()
    > But it gives this buggy warning message asking if youre sure you want
    > to close the window... don't suppose there is a way to supress that?
    >


    Nope. You can't close a window you didn't open with script.

    Don't close my windows, you don't have a problem.

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
     
    Randy Webb, May 17, 2006
    #4
  5. Randy Webb wrote:

    > [...]
    > Nope. You can't close a window you didn't open with script.
    > [...]


    Yes you can, if the link was opened in a new window

    1.htm:

    <a href="2.htm" target="_blank">


    2.htm:

    <a href="#" onclick="self.close()">Close</a>

    --
    Bart
     
    Bart Van der Donck, May 17, 2006
    #5
  6. Navillus

    Randy Webb Guest

    Bart Van der Donck said the following on 5/17/2006 1:21 PM:
    > Randy Webb wrote:
    >
    >> [...]
    >> Nope. You can't close a window you didn't open with script.
    >> [...]

    >
    > Yes you can, if the link was opened in a new window
    >
    > 1.htm:
    >
    > <a href="2.htm" target="_blank">
    >
    >
    > 2.htm:
    >
    > <a href="#" onclick="self.close()">Close</a>
    >


    Man o man, what a nice "feature" to have.
    Doesn't work with a tab in Firefox but otherwise it does. Geez.
    Opera lets you close it even in a new tab.
    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
     
    Randy Webb, May 17, 2006
    #6
  7. Bart Van der Donck wrote:

    > Randy Webb wrote:
    >> Nope. You can't close a window you didn't open with script.

    >
    > Yes you can, if the link was opened in a new window
    >
    > 1.htm:
    >
    > <a href="2.htm" target="_blank">
    >
    >
    > 2.htm:
    >
    > <a href="#" onclick="self.close()">Close</a>


    Voodoo programming at its best.


    PointedEars
    --
    This is Usenet. It is a discussion group, not a helpdesk. You post
    something, we discuss it. If you have a question and that happens to get
    answered in the course of the discussion, then great. If not, you can
    have a full refund of your membership fees. -- Mark Parnell in alt.html
     
    Thomas 'PointedEars' Lahn, May 22, 2006
    #7
  8. Navillus

    Randy Webb Guest

    Thomas 'PointedEars' Lahn said the following on 5/22/2006 5:55 PM:
    > Bart Van der Donck wrote:
    >
    >> Randy Webb wrote:
    >>> Nope. You can't close a window you didn't open with script.

    >> Yes you can, if the link was opened in a new window
    >>
    >> 1.htm:
    >>
    >> <a href="2.htm" target="_blank">
    >>
    >>
    >> 2.htm:
    >>
    >> <a href="#" onclick="self.close()">Close</a>

    >
    > Voodoo programming at its best.


    "Voodoo programming"? Where did you get that crap? It is a bug in every
    single browser anybody tested it in. Exploiting that bug isn't "Voodoo
    programming", calling it "Voodoo Programming" is, well, Voodoo at its best.

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
     
    Randy Webb, May 23, 2006
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alexey Smirnov
    Replies:
    3
    Views:
    493
    Alexey Smirnov
    May 26, 2010
  2. Replies:
    0
    Views:
    304
  3. john
    Replies:
    2
    Views:
    230
    Bob Barrows [MVP]
    Jan 30, 2006
  4. Replies:
    2
    Views:
    475
  5. Iulian Ilea
    Replies:
    1
    Views:
    323
    pcx99
    Dec 21, 2006
Loading...

Share This Page