[英]How to open a new window when clicking a hyperlink?
I would like to open a new window with height of 600px and width of 200px, after clicking on a hyperlink. 在点击超链接后,我想打开一个高度为600px,宽度为200px的新窗口。
How can I do that in HTML/Javascript? 我怎么能用HTML / Javascript做到这一点?
Do I use something like window.open? 我是否使用像window.open这样的东西? Is it compatible in IE also?
它在IE中也兼容吗? Or should I use something in Jquery?
或者我应该在Jquery中使用什么?
Thanks in advance. 提前致谢。
It's far better to attach this to the hyperlink unobtrusively, similar to: 最好不要不引人注意地将它附加到超链接上,类似于:
HTML HTML
<a href="mypopup.htm" id="popup">This will open in a new window</a>
JavaScript 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. 这种方法的好处是您只需要在HTML中指定超链接,如果JavaScript被禁用或由于某种原因产生错误,那么它将回退到仅使用标准超链接。
Creating a New Window with JavaScript (includes window size) 使用JavaScript创建一个新窗口(包括窗口大小)
http://www.fontstuff.com/frontpage/fptut06.htm http://www.fontstuff.com/frontpage/fptut06.htm
JavaScript is the best way of doing this JavaScript是执行此操作的最佳方式
var win = window.open(cant remeber this bit); var win = window.open(不能记住这一点); win.resizeTo(w, h);
win.resizeTo(w,h); win.focus();
win.focus();
window.open (URL, windowName[, windowFeatures]) window.open(URL,windowName [,windowFeatures])
winRef = window.open( URL, name [ , features [, replace ] ] )
var user_window=window.open('http://www.someplace.com','someplace_window_name','toolbar=no,directories=no,location=no,status=yes,menubar=no,resizable=yes,scrollbars=yes,width=1024,height=768');
user_window.focus();
A user click should initiate this, or it will be blocked by most popup blockers. 用户单击应启动此操作,否则大多数弹出窗口阻止程序将阻止它。 This works in all browsers I've had to support including IE6+, FF, Opera, Safari.
这适用于我必须支持的所有浏览器,包括IE6 +,FF,Opera,Safari。
The focus bit ensures that the new window is brought to the front. 焦点位确保将新窗口置于前面。
As an alternative to a popup window, I'd suggest the Dialog plugin for Jquery. 作为弹出窗口的替代方案,我建议使用Jquery的Dialog插件。
That's what I replaced 90% of my popup windows with. 这就是我用90%的弹出窗口取代的。
Your popup becomes a popover (bound within the original window), and this as far as I can tell is never blocked by a popup blocker. 你的弹出窗口变成了一个弹出窗口(绑定在原始窗口中),据我所知,它永远不会被弹出窗口阻止程序阻止。 The Dialog plugin allows dragable popovers, appearance and disappear effects, and lots of other cool stuff.
Dialog插件允许可拖动的弹出窗口,外观和消失效果,以及许多其他很酷的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.