matrixguy
matrixguy

Reputation: 306

javascript open page in new tab and new links on that same tab

Basically I have a table where if the user clicks on id it opens a link on new tab. So if user clicks on another id it should open on that earlier tab and not make another new tab

$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>

The ctrl+click works as it opens the link on new tab everytime. But how can i keep the same tab for just click ?

Upvotes: 0

Views: 96

Answers (2)

Suraj
Suraj

Reputation: 3137

You can use "_Parent" instead of "_blank" for this.

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

Hope it will help.

Upvotes: 0

vaso123
vaso123

Reputation: 12391

The window.open method has parameters:

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

If you define a name for a window, and use this on your javascript code, the named window will be replaced by the content.

Reference is here.

Upvotes: 2

Related Questions