简体   繁体   中英

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 ?

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 .

As f_puras answered right here: https://stackoverflow.com/a/12090990/3309799

When you first open the tab, give the window a name:

<script>
    this.name = "myWindowName";
</script>

Then, from your parent tab, set the target to the window name.

<a href="mypage.html" target="myWindowName">Click me</a>

Let me know if this works.

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

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

Hope it will help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM