We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


Javascript Close Popup and Redirect Parent

koolie asked
Medium Priority
Last Modified: 2008-02-01
This is my first time using my points so forgive if my question is lacking in information.

What I am trying to do is I have a popup window that opens in my shopping cart.  There are a list of links that the user can click on in this popup, but they all go to basically the same place (cart.php?partner=partnername).  What I need to have happen is when the user clicks the link that it loads that link in the parent page and closes the popup. I have it working in Firefox, but IE only closes the window and doesnt change the parent page. Additionally when the page does change/reload, the popup comes back because the page is still cart.php but just with different information after the ?

Here is the code I have to open the popup:
<script language="javascript">
window.name = "main";

function popUp(URL) {
day = new Date();
id = day.getTime();

eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=250,height=250,left = 200,top = 200');");


This is one of the links that are in the popup window:
<a href="javascript:;" target="main" onClick="opener.location='http://www.mysite.com/store/cart.php?partner=joe_smith&bid=1';window.close();">

If you need more info please ask.  Also, if someone could tell me if the amount of points given is appropriate..I dont want to short anyone :-)
Watch Question


Just a quick update:  I can get the exact same "onClick" code to work if I put it in a button, which is kind of okay but I would much so prefer a link...So the more important of the two issues is getting that link to only popup once.  Thanks
This page has a work around for MSIE.


Good luck,
Here is a cleaner approach, and the full code, just cut, paste and try this one.

<script type="text/javascript">
function open_win()
self.opener = this;

<input type=button value="Open Window" onclick="open_win()">



It's not as much an issue of getting the window to close.  I can get that done by using window.close().  What I cant get it to do is go to the new page and then close.  Thank you though...
I don't understand, youwant to open a new window and then close it?


I like the cleaner code, but I have to have this page pop open onload.  My client is concerned that if I leave it up to a user to click a button, that they wont do it.  However, could this be put into an onload event in the body tag?


The window will popup from the cart page.  The links that are inside the popup contain values after the .php? that will say who gets commission for the sale.

So  cart.php loads -->popup opens -->user clicks who gets the commision -->popup closes --> cart.php loads the link that was clicked in the popup
Have you tried this?

<a href="javascript:;" target="main" onClick="opener.location='http://www.mysite.com/store/cart.php?partner=joe_smith&bid=1';this.focus();self.opener = this;self.close();">

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


IE Still didnt like it....i dunno... The world would be a much better place if IE just floated away; however, I have managed to resolve my issue for the most part.  I still cant get to work with an <a> tag and in IE, but the buttons should be fine.  I only have 8 of them and buttons are a little more prominent anyway.  I appreciate the help and if you do by change figure it out please post it as I may need it later, but for the effort I'll throw the points u'r way...Thanks
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.