如何在JavaScript中打开新选项卡而不切换到新选项卡? [英] How to open new tab in JavaScript without switching to the new tab?

查看:97
本文介绍了如何在JavaScript中打开新选项卡而不切换到新选项卡?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在不切换到新选项卡的情况下使用javascript打开新选项卡?

例如,当用户单击链接时,将打开新选项卡,但用户应该保持打开状态当前标签。

How can I open a new tab using javascript without switching to the new tab?
For example, when a user clicks on a link a new tab is to be opened, but the user should stay on the current tab.

推荐答案

网页浏览器自动关注新标签页,但您可以调用焦点:

The web browser automatically focuses on the new tab, but you can call the focus back:

function openWindow( url )
{
  window.open(url, '_blank');
  window.focus();
}

<a href="http://www.example.com/" onclick="javascript:openWindow(this.href);return false;">Click Me</a>

这篇关于如何在JavaScript中打开新选项卡而不切换到新选项卡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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