单击超链接时如何打开新窗口?

chr*_*her 2 html javascript jquery

在点击超链接后,我想打开一个高度为600px,宽度为200px的新窗口.

我怎么能用HTML/Javascript做到这一点?

我是否使用像window.open这样的东西?它在IE中也兼容吗?或者我应该在Jquery中使用什么?

提前致谢.

Jas*_*rry 7

最好不要不引人注意地将它附加到超链接上,类似于:

HTML

<a href="mypopup.htm" id="popup">This will open in a new window</a>
Run Code Online (Sandbox Code Playgroud)

JavaScript的

window.onload = function() {
    document.getElementById("popup").onclick = function(){
        return !window.open(this.href, "pop", "width=200,height=600");
    }
}
Run Code Online (Sandbox Code Playgroud)

这种方法的好处是您只需要在HTML中指定超链接,如果JavaScript被禁用或由于某种原因产生错误,那么它将回退到仅使用标准超链接.