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 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    3
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Question 1 pop up 1 new window tab with one click?

    Hey guys,

    If you go to this site: http://www.retailmenot.com/view/jcpenney.com
    and if you click on one of those coupons it opens new window tab(merchants web site) and a pop up window with the coupon code.

    I am trying to make something similar. I am not a programmer so i'v searched for possible solutions and found this code:

    <a href="http://www.yahoo.com" onclick="javascript:void window.open('http://www.yahoo.com','1351633016625','width=250,height=5 00,toolbar=0,menubar=0,location=0,status=1,scrollb ars=1,resizable=1,right=0,top=0');return false;">Pop-up Window</a>

    I don't know what to add to be able to open one new window tab and a pop up window with one click.(i want to open google.com on new window tab and yahoo.com on a pop up window)

    Is there any way to add something or change in this code to achieve this result?

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,663
    Thanks
    80
    Thanked 4,640 Times in 4,602 Posts
    Get rid of the javascript:void

    (a) there is NEVER a need for the javascript: in an event handler
    (b) you would only use void if you wanted NOTHING AT ALL to happen.

    and other than that, just use two window.open()'s and you are done.

    Do *NOT* specify any characteristics (width, height, etc.) for the one you want to open in a new tab. *DO* specify those for the one you want to be the popup.

    Do remember to do the return false as you have it there.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    mindhuter (11-01-2012)

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,663
    Thanks
    80
    Thanked 4,640 Times in 4,602 Posts
    Or, an even simpler way:
    Code:
    <a href="http://www.google.com" target="myNewTab"
         onclick="window.open('http://www.yahoo.com','myNewPopup',
                              'width=250,height=500,toolbar=0,menubar=0,location=0,status=1,scrollb ars=1,resizable=1');
                  return true;"
    > Open Both </a>
    The target= is enough to ask that the normal href (here google.com) should open in a new window/tab [it can be either one...depends on the browser AND on the user preferences...you can't control that] and then the window.open() controls the opening of the popup. By returning true from the onclick, you are telling the <a> to go ahead and also do its normal operation, which will be to open google.com in the new tab/window.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    mindhuter (11-01-2012)

  • #4
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    3
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Can this pop up(yahoo) be in front of the new tab window(google)?

    Old Pedant, i have been reading tutorials and trying for hours on how to do this, but i don't understand programming much. Thank you very much for your help.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,663
    Thanks
    80
    Thanked 4,640 Times in 4,602 Posts
    Hmmm...I think so...

    Try this:
    Code:
    <script type="text/javascript">
    var popup = null;
    function popit( url )
    {
         popup = window.open( url, 'myNewPopup',
             'width=250,height=500,toolbar=0,menubar=0,location=0,status=1,scrollb ars=1,resizable=1'); 
        setTimeout( function() { popup.focus(); }, 1000 );
        return true;
    }
    </script>
    ...
    
    <a href="http://www.google.com" target="myNewTab" 
       onclick="return popit('http://www.yahoo.com');"> Open Both </a>
    If that doesn't work, let me know. The setTimeout there allows time for the new tab to be created and then forces the popup to the front using focus().
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    mindhuter (11-02-2012)

  • #6
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Just remeber that your visitor will have full control of where and how the new page opens via their browser settings. Any values you specify are simply suggestions.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • Users who have thanked felgall for this post:

    mindhuter (11-02-2012)

  • #7
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    3
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Works perfectly


  •  

    Posting Permissions

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