简体   繁体   English

如何在单击链接时打开新选项卡或窗口?

[英]How can I open a new tab or window when a link is clicked?

I have same ancors/hyperlink in my html file. 我的html文件中有相同的ancors / hyperlink。 These point to a new website outside my site. 这些指向我网站外的新网站。 So I want that when the user clicks the link it should open a new tab or window. 所以我希望当用户点击链接时,它应该打开一个新的选项卡或窗口。 My website page should not be closed. 我的网站页面不应该关闭。

How can it be done? 如何做呢?

open in tabs: there is nothing programatically that you can do to accomplish that, the only thing I'm thinking of is set the browser to open new links in tabs instead of new window... 在标签中打开:没有任何编程可以做到这一点,我唯一想到的是设置浏览器在标签而不是新窗口中打开新链接...

to open in a new window all you need is to place a target in your anchors 要在新窗口中打开,您只需要在锚点中放置一个目标

<a href="mydomain.com" target="_blank">click here</a>

and, by the way there are more options to the target 顺便提一下,目标还有更多的选择

target="_blank"   

opens in a new Blank window 在新的空白窗口中打开

target="_parent"  

opens in a Parent window (used when dealing with iframes and you want to open the link in other frame) 窗口中打开(在处理iframe时使用,并且您想在其他框架中打开链接)

target="_self"    

opens in it's own/ self window (used when dealing with iframes and you want to open the link in the current frame) 在它自己的/ 自我窗口中打开(在处理iframe时使用,你想打开当前帧中的链接)

target="_top"     

opens in the top of all frames (it will open on top of all frames in the page, like a no-frame page will be display) 在所有框架的顶部打开(它将在页面中的所有框架的顶部打开,就像将显示无框架页面一样)

<a href="newpage.htm" target="_blank">Click me to open in a new tab/window</a>

Load the linked document into a new blank window. 将链接的文档加载到新的空白窗口中。 This window is not named. 此窗口未命名。

If there is no existing window or frame with the same name as specified in the target, a new window is opened with a name equal to the value of the target. 如果没有与目标中指定的名称相同的现有窗口或框架,则会打开一个名称等于目标值的新窗口。

Its the setting in a browser that determines whether to open the page in a new tab or in a new window. 它是浏览器中的设置,用于确定是在新选项卡中还是在新窗口中打开页面。

Just add target="_blank" to the <a> tag 只需将target =“_ blank”添加到<a>标签即可

<a href="http://example.com" target="_blank"> Click here </a>

最简单的方法是在锚点中使用target属性并将其设置为_blank

<a href="http://www.worsethanfailure.com/" target="_blank">Worse Than Failure</a>

This is a dupe of opening links in the same window or in a new (tab) and https://stackoverflow.com/questions/118567/is-there-ever-a-good-reason-to-force-opening-a-new-browser-window . 这是在同一个窗口或新的(选项卡)打开链接的欺骗和https://stackoverflow.com/questions/118567/is-there-ever-a-good-reason-to-force-opening-a - 新浏览器窗口 Basically - no. 基本上 - 没有。 And there shouldn't be a way - you shouldn't impose your surfing preferences on unsuspecting others. 并且应该没有办法 - 你不应该把你的冲浪偏好强加给毫无戒心的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当仅在新窗口中使用javascript并在同一选项卡中使用另一个javascript单击单选按钮时,如何打开多个网页 - How can I open multiple webpages when radio button is clicked using only javascript one in new window and other in same tab 如何在用户单击时在新选项卡中打开链接 - How can I open a link in a new tab when the user clicks it 单击时如何在新的浏览器选项卡中打开下载链接并在文件下载链接出现之前在该选项卡上设置倒计时 - How do I make a download link open in a new browser tab when clicked and set a countdown on that tab before the file download link appears 当单击JavaScript和HTML时如何使链接打开新窗口? - How to make a link open a new window when clicked in JavaScript and HTML? 如何打开在新标签页中点击的链接? - How to open the link clicked in a new tab? 如何在新窗口中打开链接? - How can I open a link in a new window? 确定点击链接是否意味着打开新窗口或选项卡 - Determine on onclick whether the clicked link is meant to open a new window or tab 如何在新标签页或窗口中打开 iframe 链接 - How to open iframe link in new tab or window Amcharts-如何在新标签页/窗口中打开链接 - Amcharts - How to open link in a new tab/window 如何在启用了选项卡的新窗口中打开链接 - How to open a link in new window with tab enabled
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM