2017-01-19 13 views
0

"javascript:location.href"を使用して新しいタブを開く方法があるかどうかを判断しようとしています。リンクを開くために他の方法を使用することはできません。なぜなら、ロード時に特定のメンバーのIDを取得する必要があるからです。複数のリンクを開くため、javascript関数を作成することもできません。ここでonclick = "javascript:location.href"を使って新しいタブを開く方法?

target="_blank" //didn't work 

は、私のコードの一部です:

<a onclick="javascript:location.href='website.com' + location.search"><a/> 

これを行うには、他の方法がある場合、私に知らせてください。

+0

ない可能 '_blank'が –

+0

機能でこれを維持し、' window.open' – Manish

答えて

2

なぜwindow.openを使用しませんか?

<a onclick="window.open('website.com' + location.search)"><a/> 
+0

を使用して動作しないでしょう、これは新しいウィンドウでないタブ –

+1

@JalpeshVadgamaを開くこと:それは必要ありません。最新のブラウザでは、window.openはポップアップではなく新しいタブで開きます。プラスそれはブラウザの設定に依存します – RahulB

+0

@ JalpeshVadgamaありがとうございます。 – bigbryan

2

ofcourseあなたのシナリオはあまり簡単ではありませんが、私のスニペットを参照してください。動的に値を抽出し、それをアンカーに追加します。新しいタブで開きます。

var id = document.getElementById('id').innerHTML 
 
document.getElementById('pseudo-dynamism').href += '?id='+ id
<div id="main"> 
 
    <div id="member-details" class="question" data-answered="False"> 
 
     <span id="id">23</span> 
 
    </div> 
 
    <hr> 
 
    <a href="http://example.com" id="pseudo-dynamism" target="_blank">Click</a> \t 
 
    </div>

0

それは新しいウィンドウが開きますこれを使用します。

`<button 
onclick="window.open 
(this.href,'popUpWindow','height=600,width=600,left=10,top=10,, 
scrollbars=yes,menubar=no'); 
return false;" > 
new window 
</button>` 
関連する問題