window.open, target=_blank opens two windows

Discussion in 'Javascript' started by DonD, Aug 3, 2005.

  1. DonD

    DonD Guest

    The code:
    <a href="/art/visit/openhouse03/images/17.jpg" target="_blank"
    onclick="popCenter(this.href,'name','500','500','no'); return false;">
    <img src="/art/visit/openhouse03/images/thumb17.jpg"></a>

    The problem:
    I always get two windows. I have the required "return false". I found a
    post (http://tinyurl.com/avjlh) that addresses my exact problem, but
    they told the guy he wasn't returning false properly. That doesn't make
    any sense.

    I could hack it by targeting the same window that JS opens, but then
    I'm loading the page twice.

    I just want it call my function if the user has JS, and open a blank
    window if they don't.

    Thanks.

    --Don D.
    (not the same Don as in the link given above)
     
    DonD, Aug 3, 2005
    #1
    1. Advertising

  2. DonD

    RobG Guest

    DonD wrote:
    > The code:
    > <a href="/art/visit/openhouse03/images/17.jpg" target="_blank"
    > onclick="popCenter(this.href,'name','500','500','no'); return false;">
    > <img src="/art/visit/openhouse03/images/thumb17.jpg"></a>
    >
    > The problem:
    > I always get two windows. I have the required "return false". I found a
    > post (http://tinyurl.com/avjlh) that addresses my exact problem, but
    > they told the guy he wasn't returning false properly. That doesn't make
    > any sense.
    >
    > I could hack it by targeting the same window that JS opens, but then
    > I'm loading the page twice.
    >
    > I just want it call my function if the user has JS, and open a blank
    > window if they don't.


    I suspect something funny is happening in your popCenter() script. Try
    the following:

    <script type="text/javascript">
    function popCenter( url, n, a, b, c ){
    aWin = window.open( url, n, '');
    }
    </script>

    <a href="a.gif" target="_blank" onclick="
    popCenter(this.href,'name','500','500','no'); return false;
    "><img src="a.gif"></a>


    I can only test in IE with JavaScript on, but it worked fine in Firefox
    with scripting on or off.



    --
    Rob
     
    RobG, Aug 3, 2005
    #2
    1. Advertising

  3. DonD

    Phat G5 (G3) Guest

    in article , DonD at
    wrote on 8/2/05 5:58 PM:

    > The code:
    > <a href="/art/visit/openhouse03/images/17.jpg" target="_blank"
    > onclick="popCenter(this.href,'name','500','500','no'); return false;">
    > <img src="/art/visit/openhouse03/images/thumb17.jpg"></a>
    >
    > The problem:
    > I always get two windows. I have the required "return false". I found a
    > post (http://tinyurl.com/avjlh) that addresses my exact problem, but
    > they told the guy he wasn't returning false properly. That doesn't make
    > any sense.
    >
    > I could hack it by targeting the same window that JS opens, but then
    > I'm loading the page twice.
    >
    > I just want it call my function if the user has JS, and open a blank
    > window if they don't.
    >
    > Thanks.
    >
    > --Don D.
    > (not the same Don as in the link given above)
    >

    Don, get rid of the target="_blank" that is not needed. The javascript
    function is separate of the html function target and that is why you are
    seeing that happening.
     
    Phat G5 (G3), Aug 3, 2005
    #3
  4. DonD

    DonD Guest

    Phat G5(G3),

    I'm not sure I understand. If the user has JS turned off, I still want
    them to get a new window. I don't want the larger image to load in the
    same window. If the user does have JS, then they get my window with the
    proper sizing, etc. I can't give non-JS users a new window without
    target=_blank, can I? I don't know a way.

    --Don D.
     
    DonD, Aug 3, 2005
    #4
  5. DonD

    ?? Guest

    Then why dun u just leave the JS and use HTML on its own.


    mo


    "DonD" <> wrote in message
    news:...
    > Phat G5(G3),
    >
    > I'm not sure I understand. If the user has JS turned off, I still want
    > them to get a new window. I don't want the larger image to load in the
    > same window. If the user does have JS, then they get my window with the
    > proper sizing, etc. I can't give non-JS users a new window without
    > target=_blank, can I? I don't know a way.
    >
    > --Don D.
    >
     
    ??, Aug 3, 2005
    #5
  6. DonD

    Kevin Newman Guest

    ?? wrote:
    > Then why dun u just leave the JS and use HTML on its own.



    Because you can customize the popup in javascript in a way that you
    cannot in html. Doing it this way means it will "gracefully degrade" if
    javascript is turned off, but that you will get all the benefits if it
    is on.

    Kevin N.
     
    Kevin Newman, Aug 3, 2005
    #6
  7. DonD

    DonD Guest

    RobG,

    You're exactly right. I was calling another function within popCenter
    and it was opening the additional window. I was digging in the wrong
    place. Thanks!

    --Don D.
     
    DonD, Aug 3, 2005
    #7
  8. DonD

    Phat G5 (G3) Guest

    in article , DonD at
    wrote on 8/3/05 4:43 AM:

    > Phat G5(G3),
    >
    > I'm not sure I understand. If the user has JS turned off, I still want
    > them to get a new window. I don't want the larger image to load in the
    > same window. If the user does have JS, then they get my window with the
    > proper sizing, etc. I can't give non-JS users a new window without
    > target=_blank, can I? I don't know a way.
    >
    > --Don D.
    >

    No, you cannot. Its one way or the other. The only thing I can think of is
    to write a function that will loop thru all windows looking for one with
    your url and if not found then pop a new one. It'd take some work but
    doable.

    -Steffan
     
    Phat G5 (G3), Aug 5, 2005
    #8
  9. DonD

    Phat G5 (G3) Guest

    in article 42f0ca93$1@127.0.0.1, ?? at wrote on 8/3/05 6:47 AM:

    > Then why dun u just leave the JS and use HTML on its own.
    >
    >
    > mo
    >
    >
    > "DonD" <> wrote in message
    > news:...
    >> Phat G5(G3),
    >>
    >> I'm not sure I understand. If the user has JS turned off, I still want
    >> them to get a new window. I don't want the larger image to load in the
    >> same window. If the user does have JS, then they get my window with the
    >> proper sizing, etc. I can't give non-JS users a new window without
    >> target=_blank, can I? I don't know a way.
    >>
    >> --Don D.
    >>

    >
    >

    Earlier in this thread he is using a JS function to pop the window centered
    and sized.
     
    Phat G5 (G3), Aug 5, 2005
    #9
    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. Matt
    Replies:
    4
    Views:
    3,498
    Whitecrest
    Jun 1, 2004
  2. John A Grandy
    Replies:
    5
    Views:
    9,271
    Laurent Bugnion
    May 8, 2006
  3. Donald Welker

    Form Target is _blank so grid pager opens new window

    Donald Welker, Jun 24, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    160
    Donald Welker
    Jun 24, 2005
  4. Matt
    Replies:
    1
    Views:
    167
    Evertjan.
    Jun 1, 2004
  5. MPH

    window.open() opens two windows

    MPH, Apr 28, 2005, in forum: Javascript
    Replies:
    13
    Views:
    176
    Evertjan.
    May 4, 2005
Loading...

Share This Page