Self close a Pop-Up -> then opening link in a new browser window?

Hi folks,

I have a couple of Pop-Ups which contain links. These links should self close the Pop-Up, and then open up a new browser window to follow the link. I’m using the following function - but where do I specify that a new browser window should be used when someone clicks on the link (basically like a target: blank)?


function goAndClose(url) {
  opener.location.href = url
  this.close;
}

and the link in the Pop-Up is marked like this:


<a href="javascript:self.close();" onclick="goAndClose('http://www.google.com/')">Google</a>

Can someone help me out?

And by the way: does someone know if its actually possible to force up opening a new browser tab (in IE7/Firefox) instead of a new browser window??

That code will open the URL in the window that opened the popup.

You open a new window with window.open(). You can then close the current window with window.self.close();

But, in general, I’d recommend you avoid popups where possible.

Thanks for your input! Yeah, I’m also not a fan of pop ups, but in this case it’s how the client wants it: its actually an image gallery. Each image opens up in a pop up and has a link underneath - to an external website.
Clicking this link should close the pop up and open up the website in a new browser window…

Sorry, but do you mind giving me a code example? I’m not really good in JS and cant get it right :frowning:


function goAndClose(page) {
  //opener.location.href = page
   window.open(page, "mywindow");
  //this.close;
  window.self.close();
}

doesnt really work… can u help me out?

Big Thx!

OK - this is completely untested, but it’s got a little progressive enhancement…


function goAndClose() {
window.opener.location.href=this.href;
window.self.close();
}

The HTML would then be:

<a href="http://www.google.com/" onclick="goAndClose();">Google</a>

Hope that helps.

Hi ceeb,

thanks for your reply… I tried the code snippet (and a couple of modifications), but unfortunately it didn’t work :frowning:

Can someone else maybe help out? :frowning:

Again, here’s what I’m looking for:

function which first closes the pop-up by clicking on a link, then opening up a new browser window which opens up the link.

any input is highly appreciated!

This worked in IE6. and opened the new page in FF. I didn’t open a popup to use it but it will work better with one.


<script language="javascript" type="text/javascript">
<!--
function goAndClose(page) {

   window.open(page);
    window.close(name_of_Popup);//insert the name of the popup
//window here.  will only work properly if popup was created with window.open.
//havent gotten it to work in ff but I started with the window to be closed
//didnt open a popup to start...
}
</script>
<a href="javascript:void();" onclick="goAndClose('http://www.google.com/');">Google</a>

here is a refrence of windows metodshttp://www.devguru.com/…QuickRef/window.html
hope this helps