基本上我有一个表,如果用户点击id,它会在新标签上打开一个链接。因此,如果用户点击另一个ID,它应该在之前的标签上打开,而不是另一个新标签
$scope.navigationUrl = function (event,item) {
if (event.ctrlKey) {
window.open('link' + item,"_blank"); // in new tab
} else {
$location.path('link' + item); // in same tab , yeah, this is completely wrong
}
;
<tbody>
<tr ng-repeat="case in LastBuild">
<td colspan="1" ng-click="navigationUrl($event,case.id)">{{case.id}}</td>
<td colspan="1">{{case.TimeTaken}}</td>
</tr>
</tbody>
ctrl + click工作,因为它每次都会打开新标签上的链接。但是如何才能保持相同的标签只需点击?
答案 0 :(得分:2)
window.open
方法有参数:
window.open(URL,name,specs,replace)
如果为窗口定义名称,并在javascript代码上使用此名称,则命名窗口将替换为内容。
参考是here。
答案 1 :(得分:0)
正如f_puras在这里回答:https://stackoverflow.com/a/12090990/3309799
首次打开选项卡时,请为窗口命名:
<script>
this.name = "myWindowName";
</script>
然后,从父选项卡中,将目标设置为窗口名称。
<a href="mypage.html" target="myWindowName">Click me</a>
让我知道这是否有效。
答案 2 :(得分:0)
您可以使用“_Parent”代替“_blank”。
if (event.ctrlKey) {
window.open('link' + item,"_Parent"); // in new tab
}
希望它会有所帮助。