Javascript 如何将超链接作为具有给定宽度和高度的弹出窗口打开?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4243216/
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 11:33:13  来源:igfitidea点击:

How can I make a hyperlink open as a popup with a given width and height?

javascripthtmlcss

提问by Bipin

I have a hyperlink that is:

我有一个超链接是:

 <a href="some.html">Test</a>

If I click on the Test link, some.htmlshould open as pop up menu with some given width & height.

如果我单击“测试”链接,some.html则应以具有给定宽度和高度的弹出菜单打开。

How can I do this?

我怎样才能做到这一点?

采纳答案by Fred

Using target='_blank'sometimes opens in a new tab, and it usually does for Firefox and Chrome. Your best best is to use Frédéric's code:

使用target='_blank'有时会在新标签页中打开,通常适用于 Firefox 和 Chrome。最好的方法是使用 Frédéric 的代码:

<a href="javascript:window.open('some.html', 'yourWindowName', 'width=200,height=150');">Test</a>

回答by Frédéric Hamidi

You can use window.open():

您可以使用window.open()

<a href="javascript:window.open('some.html', 'yourWindowName', 'width=200,height=150');">Test</a>

Or:

或者:

<a href="#" onclick="window.open('some.html', 'yourWindowName', 'width=200,height=150');">Test</a>

回答by Sarfraz

To open in popup, you can use target="_blank":

要在弹出窗口中打开,您可以使用target="_blank"

<a href="some.html" target="_blank">Test</a>

Or use window.open:

或使用window.open

<a href="#" onclick="window.open('some.html', 'win', 'width=400,height="400"')">Test</a>

回答by Mohamed Saligh

easy way to implement without the anchor element and without the new popup window toolbar

在没有锚元素和新的弹出窗口工具栏的情况下实现的简单方法

<span class="popup" onClick="javascript:window.open('http://www.google.com', '_blank','toolbar=no,width=250,height=250');">

回答by Kijiya

Try use this code :

尝试使用此代码:

<a href="javascript: void(0)" onclick="window.open('yourLink','_blank','width=900,height=300');">Try</a>

Using javascript: void(0)to make no any contact of previous page after you click popup window.

使用javascript: void(0)你点击弹出窗口后,使以前没有页面的任何接触。