简体   繁体   English

链接打开选项卡时如何留在当前选项卡上? Javascript

[英]How to stay on current tab when a link opens a tab? Javascript

There are many posts on this, but none seem to have a solution.I think it can be done.这方面有很多帖子,但似乎没有一个解决方案。我认为可以做到。

If you have a link with target='_blank' , the page will open in a new tab, and it will be in focus.如果您有一个带有target='_blank'的链接,则该页面将在新选项卡中打开,并且将成为焦点。

However, if you press the CTRL key when you click that link, the new tab will be in the background.但是,如果您在单击该链接时按下CTRL键,则新选项卡将位于后台。 Therefore, if you can use JavaScript to simulate a CTRL press, it should work.因此,如果您可以使用 JavaScript 来模拟CTRL按下,它应该可以工作。

I saw someone post a code trying this, but it was old and used initMouseEvent which is depreciated.我看到有人发布了一个尝试这个的代码,但它很旧并且使用initMouseEvent ,它已经被贬值了。 I think that's why it didn't work.我认为这就是它不起作用的原因。 Could there be a simple way to do this, something like...有没有一种简单的方法可以做到这一点,比如......

<a href='https://example.com' onclick='...code to simulate CTRL key here...'>CLICK ME</a>

There is no way to make this work in modern browsers anymore.再也无法在现代浏览器中进行这项工作了。 All the methods that existed are deprecated and should not be used.所有存在的方法都已弃用,不应使用。

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

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