【问题标题】:javascript open page in new tab and new links on that same tabjavascript在新选项卡中打开页面并在同一选项卡上打开新链接
【发布时间】:2017-01-05 06:01:22
【问题描述】:

基本上我有一个表格,如果用户点击 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 每次都会在新选项卡上打开链接。但是我怎样才能保持相同的标签只点击?

【问题讨论】:

    标签: javascript


    【解决方案1】:

    window.open 方法有参数:

    window.open(URL,name,specs,replace)
    

    如果您为窗口定义了一个名称,并在您的 javascript 代码中使用它,则命名的窗口将被内容替换。

    参考是here

    【讨论】:

    • 这很简单,我正在尝试一些愚蠢的事情。谢谢。
    【解决方案2】:

    您可以为此使用“_Parent”而不是“_blank”。

    if (event.ctrlKey) {
            window.open('link' + item,"_Parent"); // in new tab
    }
    

    希望它会有所帮助。

    【讨论】:

      猜你喜欢
      • 2020-12-11
      • 2012-04-25
      • 2020-12-07
      • 1970-01-01
      • 2014-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-23
      相关资源
      最近更新 更多