How to stay on current window when the link opens in new tab?

前端 未结 7 1896
走了就别回头了
走了就别回头了 2020-12-01 15:54

When a user clicks on a link

click

is there a way to stay on the

相关标签:
7条回答
  • 2020-12-01 16:33

    I guess target="_blank" would open new tab/Windows but will switch the tab as well, and no way I can find them stuff in html, Yes but when we click in link pressing control key it opens the link in new background tab, Using javascript we can stimulate same Here is code I found

    function openNewBackgroundTab(){    
        var a = document.createElement("a");    
        a.href = "http://www.google.com/";    
        var evt = document.createEvent("MouseEvents");    
    
        //the tenth parameter of initMouseEvent sets ctrl key    
        evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0,true, false, false, false, 0, null);    
        a.dispatchEvent(evt);
    }
    
    0 讨论(0)
提交回复
热议问题