簡體   English   中英

在新選項卡中打開鏈接,但焦點應保留在當前頁面上

[英]Open a link in new Tab but focus should remain on the current Page

我們有一個鏈接,如果我們單擊該鏈接,則按 ctrl 鍵,應該會打開一個新選項卡,但我們希望我們的焦點應該在主屏幕(當前屏幕)上。

我們嘗試了各種建議的選項,例如:

var currentWindow = window;

var newWindow = window.open("", "_blank");
newWindow.location = `/dashboard/agency/${c.id}`;
newWindow.blur();

currentWindow.focus();

但沒有任何工作正常,點擊后,此鏈接會在新選項卡中打開,並且控件也會轉到該選項卡,而不是停留在當前屏幕上。 有什么想法嗎?

為確保焦點保持在主屏幕上,您可以在單擊鏈接后在主屏幕上使用 JavaScript 調用 window.focus() function。 Javascript Window.focus()方法用於聚焦新打開的window。

<a href="https://example.com" target="_blank" onclick="window.focus();">Open in new tab</a>

你也可以看看那個問題。 window.focus() 在 javascript

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM