簡體   English   中英

jQuery模擬Ctrl +單擊事件時打開新選項卡時單擊

[英]jQuery simulate ctrl + click when opening new tab on click event

我在jQuery中編寫了以下代碼:

  $(document).on("click", "#datatable-responsive tbody tr td button.btn", function () {
     window.open('somelinkhere', '_blank');
  });

所以這里的問題是當我這樣操作時,它可以完美地工作,打開的新選項卡將成為焦點,而我不希望這種情況發生。 相反,我想模擬這兩個按鍵:Ctrl +鼠標左鍵

這樣我的主窗口將保持焦點並打開新標簽頁...

我如何在jQuery中做到這一點?

一種解決方案可能是:

$(document).ready(function() {
 $("#datatable-responsive tbody tr td button.btn").click(function() {
    var thisWind = window.location;
    window.location = ('http://www.google.lt');
    window.open(thisWind, '_blank');
 });    
})

非常簡單-首先將窗口位置更改為彈出網址,然后重新打開主窗口。

您可以創建錨元素並觸發ctrl + click該元素:

$("<a/>", {href: "https://www.google.com/"}).get(0)
    .dispatchEvent(new MouseEvent("click", {ctrlKey: true}));

暫無
暫無

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

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