2017-10-08 31 views
0

我想創建一個完整的Div可點擊並鏈接到一個新的選項卡。到目前爲止,我已經取得了DIV點擊發送到新的鏈路與此代碼jQuery使整個Div可點擊鏈接_blank

$(document).ready(function(){ 
     $('.wish-list').click(function(){ 
      location.href = 'https://link.com' 
    }) 
    }); 

此作品送你到鏈接的頁面,但我希望做同樣的動作,但打開一個新的標籤。

非常感謝您的幫助。

+0

使用' 'window.location.href =「http://link.com」;'' –

+0

@RakeshRaj嘿感謝,但仍然只是在同一窗口中打開鏈接,我試圖打開它在一個新的標籤,試圖創建「target = _blank」事件 –

+0

使用這個''window.open('https://link.com','_blank');'' –

回答

3

您可以使用window.open

window.open("http://link.com", "_blank"); 
+0

這個作品完美,謝謝! –

2

您可以使用此:

window.open('url', '_blank'); 
+0

這工作完美,謝謝! –

1

window.open

用這個代替location.href

window.open(strUrl, strWindowName[, strWindowFeatures]); 

示例

window.open('http://www.google.com','_blank'); 
+0

這工作完美,謝謝! –

+0

'_blank'不需要作爲window.open()的第二個參數。只要沒有設置「寬度」或「高度」,窗口將打開全尺寸(新選項卡)。 –

0

您需要使用window.open()。下面的代碼片段將不會在堆棧溢出片段環境由於沙盒工作,但你可以看到它的工作here

$(function(){ 
 
    $('.link').on("click", function(){ 
 
    window.open(this.dataset.url); 
 
    }); 
 
});
.link { 
 
    cursor:pointer; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="link" data-URL="http://espn.com">ESPN</div>

0

試試這個

window.open('url', '_blank');