点击超链接时如何打开新窗口? [英] How to open a new window when clicking a hyperlink?
问题描述
我如何在HTML / Javascript中做到这一点?
我使用类似window.open的东西吗?它在IE中也兼容吗?或者我应该在Jquery中使用某些东西?
感谢您的提前支持。
<
$ b HTML
$ b $这样更好地将它连接到超链接上,类似于: b
< a href =mypopup.htmid =popup>这会在新窗口中打开< / a>
JavaScript
window.onload = function(){
document.getElementById(popup)。onclick = function(){
return!window.open(this。 href,pop,width = 200,height = 600);
}
}
这种方法的好处是您只需要在HTML中指定超链接,如果JavaScript被禁用或由于某种原因产生错误,那么它将回退到仅使用标准超链接。
I would like to open a new window with height of 600px and width of 200px, after clicking on a hyperlink.
How can I do that in HTML/Javascript?
Do I use something like window.open? Is it compatible in IE also? Or should I use something in Jquery?
Thanks in advance.
It's far better to attach this to the hyperlink unobtrusively, similar to:
HTML
<a href="mypopup.htm" id="popup">This will open in a new window</a>
JavaScript
window.onload = function() {
document.getElementById("popup").onclick = function(){
return !window.open(this.href, "pop", "width=200,height=600");
}
}
The benefit of this approach is that you only have to specify the hyperlink in your HTML, and if JavaScript is disabled or produces an error for some reason then it will fallback to just using a standard hyperlink.
这篇关于点击超链接时如何打开新窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!