打开一个链接打开一个新窗口(不是选项卡) [英] Make a link open a new window (not tab)

查看:130
本文介绍了打开一个链接打开一个新窗口(不是选项卡)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让一个链接打开一个新的浏览器窗口(不是标签)而不使用javascript?

strong>使用纯HTML 不能影响这一点 - 每个现代浏览器(=用户)都可以完全控制这种行为,因为它过去曾被滥用过......



anchor元素有一个属性 target *。您正在查找的值是 _blank **。

 < a href =www.example.com/example.htmltarget =_ blank>链接文字< / a> 

它打开一个新窗口(HTML4)或一个新的浏览上下文(HTML5)。但是,现代浏览器中的浏览上下文大多是新标签而不是新窗口。您对此没有影响,并且您无法强制浏览器打开新窗口。

另一方面,强制一个新窗口可以通过javascript - 请参阅下面的Ievgen解答一个JavaScript解决方案。但是,请注意,通过JavaScript打开窗口(如果不是在来自锚点元素的onclick事件中执行的话)可能会被弹出窗口阻止程序阻止!


(*)这个属性可以追溯到浏览器没有标签并且使用框架集是最先进的时代。与此同时,此属性的功能稍有变化(请参阅 MDN Docu (**)还有一些其他值不再有意义了(因为它们是用framesets设计的),比如 _parent _self _top


Is there a way to make a link open a new browser window (not tab) without using javascript?

解决方案

With pure HTML you can't influence this - every modern browser (= the user) has complete control over this behavior because it has been misused a lot in the past...

The anchor element has an attribute target*. The value you are looking for is _blank**.

<a href="www.example.com/example.html" target="_blank">link text</a>

It opens a new window (HTML4) or a new browsing context (HTML5). However, browsing context in modern browsers is mostly "new tab" instead of "new window". You have no influence on that, and you can't "force" the browser to open a new window.

On the other hand, forcing a new window is possible via javascript - see Ievgen's answer below for a javascript solution. However, be aware, that opening windows via javascript (if not done in the onclick event from an anchor element) are subject to getting blocked by popup blockers!

(*) This attribute dates back to the times when browsers did not have tabs and using framesets was state of the art. In the meantime, the functionality of this attribute has slightly changed (see MDN Docu)

(**) There are some other values which do not make much sense anymore (because they were designed with framesets in mind) like _parent, _self or _top.

这篇关于打开一个链接打开一个新窗口(不是选项卡)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆