View Full Version : 1 pop up 1 new window tab with one click?

10-31-2012, 10:49 PM
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?

Old Pedant
11-01-2012, 12:05 AM
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.

Old Pedant
11-01-2012, 12:10 AM
Or, an even simpler way:

<a href="http://www.google.com" target="myNewTab"
'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.

11-01-2012, 01:27 AM
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.

Old Pedant
11-01-2012, 08:40 PM
Hmmm...I think so...

Try this:

<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;

<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().

11-01-2012, 11:31 PM
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.

11-02-2012, 12:49 AM
Works perfectly