Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript: Close Popup, Open New Window & Redirect

I would like to close the current popup, open a new window (tab) and redirect to a specific link. This works extremly easy with my <a> links. I simply add "target="_blank"" and it works just fine (it doesnt close the pop up actually, but minimizes it and thats fine too).

Since I am using some buttons with a onclick function, I want to implent the "target="_blank" in the button somehow... The button looks like this at the moment:

<input type="button" onclick="parent.window.opener.location='http://google.com'; window.close();">

This works, but the problem is that it redirects in the parent window and doesnt open a new window...

Any1 has an idea how to get the feature of "target="_blank" so that a click on button will open a new window and than redirect instead of redirecting the parent window?

like image 765
Andrej Avatar asked Mar 11 '11 14:03

Andrej


2 Answers

Why not just use this in your onclick:

<input type="button" onclick="window.open('http://google.com'); window.close();" />
like image 89
JamesHalsall Avatar answered Oct 26 '22 12:10

JamesHalsall


$('#button').click(function(e)
{
 e.preventDefault();
 window.open('http://www.facebook.com/','_blank');
});

<input type="button" id="button" value="Go facebook">

It works un IExplorer, Firefox, Chrome, Opera and Safari

like image 20
Marcelo Avatar answered Oct 26 '22 14:10

Marcelo