Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts

    Target blank and close popup window

    I have a popup window that has a "link" inside it, which needs to have a target=_blank
    but when ever clicked in IE, it stays inside the same window.

    I tried all of the following, none work

    PHP Code:
    <a href='http://www.myurl.net' onclick='window.close();' target='_blank'>

    <
    a href="http://www.myurl.net" target="_blank" onClick="javascript:window.close()">

    <
    a href="http://www.myurl.net" target="_blank" onClick="javascript: setTimeout(window.close, 10);"
    Thanks
    Sonny

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Despite the similar sounding names, Java is not the same as Javascript.
    Moving from Java forum to Javascript forum.

  • #3
    Regular Coder hdewantara's Avatar
    Join Date
    Aug 2009
    Location
    Jakarta, Indonesia.
    Posts
    375
    Thanks
    9
    Thanked 55 Times in 54 Posts
    Shouldn't window.close() be used only on window opened with window.open() ?

  • #4
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by hdewantara View Post
    Shouldn't window.close() be used only on window opened with window.open() ?
    I'm trying to close a popup window from within, and open a target blank
    to help with clutter.

    Sonny

  • #5
    Regular Coder
    Join Date
    Apr 2005
    Location
    Texas
    Posts
    448
    Thanks
    24
    Thanked 63 Times in 63 Posts
    to close a popup window from within:
    Code:
    <a href="self.close ()">Close this Window</a>

  • #6
    Regular Coder
    Join Date
    Apr 2005
    Location
    Texas
    Posts
    448
    Thanks
    24
    Thanked 63 Times in 63 Posts
    I think hdewantara was saying that window.whatever() will act on a window opened from the calling script - not the scripts own window.

    //Edit
    wait, I'm not right... I think that there are some methods that work on its own window, I was too quick to say that...
    Last edited by blaze4218; 09-19-2011 at 08:31 PM.

  • #7
    Regular Coder
    Join Date
    Apr 2005
    Location
    Texas
    Posts
    448
    Thanks
    24
    Thanked 63 Times in 63 Posts
    what is your goal here? Are you closing one popup only to open another? which window is controlling all of this? could you re-use the same popup instead?

  • #8
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by blaze4218 View Post
    what is your goal here? Are you closing one popup only to open another? which window is controlling all of this? could you re-use the same popup instead?
    No I can't reuse the popup window, that would be easy but not practical for this.


    I'm closing the popup window, and at the "same time" opening a "non popup" normal everyday target=_blank link when the user clicks on a link from within the popup window

    Sonny
    Last edited by sonny; 09-19-2011 at 08:52 PM.

  • #9
    Regular Coder
    Join Date
    Apr 2005
    Location
    Texas
    Posts
    448
    Thanks
    24
    Thanked 63 Times in 63 Posts
    I'm sorry if I don't quite grasp your terminology, but where is this "'non popup' normal everyday target=_blank link"?
    By my estimates you have the original window (windowA) that opens a new window (windowB). windowB has the link <a href='http://www.myurl.net' onclick='window.close();' target='_blank'>Click me!</a> which triggers a chain reaction of
    1) a new window (windowC) is opened with url 'http://www.myurl.net'
    2) windowB closes itself
    3) windowA remains the unchanged
    If that is what you need, then all 3 worked when I ran them...

    If, on the other-hand, your intentions were
    1) windowB changes windowA's url to 'http://www.myurl.net'
    2) windowB closes itself
    then you might try this:
    Code:
    <a href='javascript:window.opener.location="http://www.myurl.net";window.close();'> Click me!</a>
    and forget about that target blank thingy, because it won't allow windowB to close.

  • #10
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by blaze4218 View Post
    I'm sorry if I don't quite grasp your terminology, but where is this "'non popup' normal everyday target=_blank link"?
    By my estimates you have the original window (windowA) that opens a new window (windowB). windowB has the link <a href='http://www.myurl.net' onclick='window.close();' target='_blank'>Click me!</a> which triggers a chain reaction of
    1) a new window (windowC) is opened with url 'http://www.myurl.net'
    2) windowB closes itself
    3) windowA remains the unchanged
    If that is what you need, then all 3 worked when I ran them...

    If, on the other-hand, your intentions were
    1) windowB changes windowA's url to 'http://www.myurl.net'
    2) windowB closes itself
    then you might try this:
    Code:
    <a href='javascript:window.opener.location="http://www.myurl.net";window.close();'> Click me!</a>
    and forget about that target blank thingy, because it won't allow windowB to close.
    Know what, I just read a article about popups being bad for users in general and I agree,
    I am going to bite the bullet and redesign without using any. if I do, it will only be for something really special like a print page or something.

    What I was trying to do, was really quite simple to understand, I gave the three links I tried
    this one below actually "WORKS" perfect in Firefox,
    PHP Code:
    <a href="http://www.myurl.net" target="_blank" onClick="javascript: setTimeout(window.close, 10);"

    BUT, IE for some reason always, opens the target blank window in the same dimensions as the popup.

    This method you gave will not work if the user has javascript turned off, and bad for SEO I do not recommend anyone use this
    PHP Code:
    <a href='javascript:window.opener.location="http://www.myurl.net";window.close();'Click me!</a
    Thanks for weighing in, those links I posted should be useful to someone down the road
    Sonny

    Ok, let me explain just for the record, your reading something in a popup window, you then
    click a link, you then go to a normal page, and the popup you were reading at gets closed.
    Last edited by sonny; 09-19-2011 at 10:31 PM.

  • #11
    Regular Coder
    Join Date
    Apr 2005
    Location
    Texas
    Posts
    448
    Thanks
    24
    Thanked 63 Times in 63 Posts
    Quote Originally Posted by sonny View Post
    Ok, let me explain just for the record, your reading something in a popup window, you then
    click a link, you then go to a normal page, and the popup you were reading at gets closed.
    I'm tempted to say: that is what I tried to say with my second example.
    But I won't quibble, I'm just glad you've read that article and come around to the light. I didn't want to say that and get all preachy, I just wanted to try and help you with your code.
    On a side note, I don't recommend that code either. I didn't think about the SEO ramifications, but it was the only variation of 10-or-so that compensated for that IE bug you were talking about...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •