Load New Page In Parent / Close Popup Window

I've added the following script to a popup window that's opened when a link in it's parent is clicked:

   function OpenInMain(mainurl) {
     window.opener.location=mainurl;
     return;
   }

with the following link:

<A HREF="javascript:OpenInMain('http://www.newsite.com/')" onClick="window.close();">New Site</A>

This loads a new page in the parent window, but it won't close the popup window. How can I do that at the same time?
lhuttonAsked:
Who is Participating?
 
a.marshConnect With a Mentor Commented:
Change the function to this:

  function OpenInMain(mainurl) {
    window.opener.location=mainurl;
    window.opener.focus();
    window.close();
    return;
  }

and change the link to:

<A HREF="javascript: OpenInMain('http://www.newsite.com/');">New Site</A>


:o)

Ant
0
 
lhuttonAuthor Commented:
Ah! I tried window.close(); in the script but didn't even think of using window.opener.focus(); as well!

Cheers :)
0
 
a.marshCommented:
Glad to help. :o)

Ant
0
All Courses

From novice to tech pro — start learning today.