How to open new tab in JavaScript without switching to the new tab?

前端 未结 8 1067
时光取名叫无心
时光取名叫无心 2020-11-29 04:11

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

8条回答
  •  情书的邮戳
    2020-11-29 04:49

    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();
    }
    
    Click Me
    

提交回复
热议问题