简体   繁体   English

在新标签页中打开此页面

[英]Open this page in new tab

Is it possible to make a web page so that it opens in a specific tab when it is opened from a hyperlink? 通过超链接打开网页时,是否可以使网页在特定选项卡中打开? Ideally with a given target name. 理想情况下使用给定的目标名称。

If one has control over the calling page(s) that link to the site, it's possible to specify the _target attribute <a href="https://mypage.com/resource/{{id}}" _target="{{id}}" 如果可以控制链接到该站点的调用页面,则可以指定_target属性<a href="https://mypage.com/resource/{{id}}" _target="{{id}}"

In this case, is it possible for the destination page https://mypage.com/resource/{{id}} to say "I'd like to open in a new tab with this specific target" regardless from where it's linked to? 在这种情况下,目标网页https://mypage.com/resource/{{id}}可能会说“我想使用此特定目标在新标签页中打开”,无论链接到何处?

No, you can not achieve this functionality from javascript. 不,您无法通过javascript实现此功能。

However this can be achieved by message passing using browser extension. 然而,这可以通过使用浏览器的扩展的消息传递来实现。

Browser extension with proper permission to access tabs you can inject dynamic code. 具有适当权限的浏览器扩展程序可以访问选项卡,您可以注入动态代码。

But this can not be achieved just from javascript 但这不能仅通过javascript来实现

I think this is the best you can do, open in a new window. 我认为这是您能做的最好的事情,在新窗口中打开。 I typically have to do this when using an API or something that doesn't allow for use in anything but the Chrome browser, so I use a link to open in chrome. 我通常在使用API​​或不允许在Chrome浏览器以外的任何东西上使用时执行此操作,因此我使用链接以chrome打开。

Using something like: 使用类似:

window.open(url,'_blank');
window.open(url);

No, you can't quite override other tabs, if that's what you're asking. 不,如果您要问的话,您不能完全覆盖其他标签。 You can, however, open your link in a fresh tab like this: 但是,您可以像这样在新标签中打开链接:

    <a href="http://www.mypage.com/" target="_blank">

If you really need to, you can look into using cookies, but that's somewhat difficult to use in this situation. 如果确实需要,可以考虑使用Cookie,但是在这种情况下使用它有些困难。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM