[removed] Close Popup, Open New Window & Redirect

2020-02-26 12:41发布

问题:

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?

回答1:

Why not just use this in your onclick:

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


回答2:

$('#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



回答3:

jQuery code:

$(function(){
    $('#button').click(function() {
        window.close();
        window.open('http://www.google.com/'); 
    });
});

HTML code:

<input type="button" id="button" value="click me">

It works OK in Chrome and IE. In Firefox, you must open this code with window.open.



回答4:

Try this:

<a href='http://google.com' onclick='window.close();' target='_blank'>LINK</a>