简体   繁体   English

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

[英]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])

More infos here 这里有更多的信息

winRef = window.open( URL, name [ , features [, replace ] ] )

来源: http//www.javascripter.net/faq/openinga.htm

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.

相关问题 在屏幕上单击时打开全新的窗口 - Open totally new window when clicking on screen 如何通过点击广告在新窗口中打开链接? - how to open a link in new window by clicking on ad? 单击功能区按钮时如何在新选项卡而不是新窗口中打开Web资源 - How to open a web resource in a new tab instead of a new window when clicking a ribbon button 如何在tinymce文本编辑器下打开新窗口中的超链接? - How to open hyperlink in new window under tinymce text editor? 如何强制 IFrame 内的超链接打开新窗口? - How to force a hyperlink inside IFrame to open into a new window? 单击超链接时,我想以全屏模式打开另一个 chrome 窗口 - I want to open another chrome window in full screen mode when clicking on a hyperlink 单击时如何重定向新选项卡或(新窗口)中的超链接? - how to redirect the hyperlink in a new tab or(new window) when clicked? window.open在单击按钮打开新窗口时发出错误 - window.open giving an error when clicking button to open new window 如何禁用鼠标中键单击超链接以在新选项卡或新窗口中打开? - How to disable mouse middle button click on hyperlink to open in a new tab or new window? 单击Ajax可排序表的行时如何打开“信息窗口” - How to open Info Window when clicking a row of an Ajax sortable table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM