4个回答

13
为什么不直接在你的onclick中使用这个:
<input type="button" onclick="window.open('http://google.com'); window.close();" />

这似乎非常好用!非常感谢!我只是被所有不同的可能性搞混了,没有想到简单的方法! - Andrej

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

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

它能够在IE、Firefox、Chrome、Opera和Safari中正常工作。


2

jQuery代码:

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

HTML 代码:

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

这段代码在Chrome和IE中能正常工作。但在Firefox中,你需要使用window.open函数打开它。


0

试试这个:

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

嗨,感谢您的快速回复,但请在回答之前阅读我的问题!target='_blank'可以正常工作,但我无法使用<input type='button' target='_blank' ....... - Andrej
不,你不能这样做。你可以在按钮的 onclick 事件上使用 window.open()。 - Naftali

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接