Javascript 在 HTML 中为 target="_blank" 打开新窗口

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2541392/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 00:49:06  来源:igfitidea点击:

Opening new window in HTML for target="_blank"

javascripthtmlcsstemplatesanchor

提问by TIMEX

<a href="facebook.com/sharer" target="_blank" >Share this</a>

How do I make this a certain width and height, in a new window, when the user clicks on it? In firefox, the current code only opens up a new tab (not a new window)

当用户单击它时,如何在新窗口中使其具有特定的宽度和高度?在firefox中,当前代码只打开一个新标签(不是新窗口)

回答by Marcos Placona

To open in a new windows with dimensions and everything, you will need to call a JavaScript function, as target="_blank" won't let you adjust sizes. An example would be:

要在带有尺寸和所有内容的新窗口中打开,您需要调用 JavaScript 函数,因为 target="_blank" 不会让您调整尺寸。一个例子是:

<a href="http://www.facebook.com/sharer" onclick="window.open(this.href, 'mywin',
'left=20,top=20,width=500,height=500,toolbar=1,resizable=0'); return false;" >Share this</a>

Hope this helps you.

希望这对你有帮助。

回答by Pekka

You can't influence neither type (tab/window) nor dimensions that way. You'll have to use JavaScript's window.open()for that.

您不能以这种方式影响类型(选项卡/窗口)和尺寸。为此,您必须使用 JavaScript 的window.open()

回答by Ben Zotto

You don't have that kind of control with a bare atag. But you can hook up the tag's onclickhandler to call window.open(...)with the right parameters. See here for examples: https://developer.mozilla.org/En/DOM/Window.open

你没有那种带有裸a标签的控制权。但是您可以连接标签的onclick处理程序以window.open(...)使用正确的参数进行调用。有关示例,请参见此处:https: //developer.mozilla.org/En/DOM/Window.open

I still don't think you can force window over tab directly though-- that depends on the browser and the user's settings.

我仍然认为您不能直接强制窗口覆盖选项卡 - 这取决于浏览器和用户的设置。