Command-Click To Open Links In New Tab/Window

1,412 views
Skip to first unread message

Owen M

unread,
Jul 25, 2013, 1:48:51 PM7/25/13
to ang...@googlegroups.com
Feeling dumb for getting stumped on this one.

Have a routeProvider:
    $routeProvider
      .when('/', {
        templateUrl: 'views/home.html',
        controller: 'HomeCtrl'
      })
      .when('/detail/:id', {
        templateUrl: 'views/detail.html',
        controller: 'DetailCtrl'
      })

index page has an ng-view and in home.html I have a link in the form <a href="/#/detail/{{item.id}}"> which works great when clicking on it.

Issue I'm having is when command clicking the link to open it in a new window it just opens it in the same window. I'm fully aware that doing so would cause the entire "app" to reinstate itself. Dug into documentation and code, but I'm stumped. Feeling really dumb on this one. Right clicking and explicitly saying to open in a new window/tab works fine. How do I get command click working?
Message has been deleted

Larry Clapp

unread,
Jul 26, 2013, 8:53:55 AM7/26/13
to ang...@googlegroups.com
Stupid question / sanity check: Does command-click work to open links on other pages in new windows?  Just checking.

And, maybe using ng-href would help:

The buggy way to write it:
 
<a href="http://www.gravatar.com/avatar/{{hash}}"/>
 
The correct way to write it:
 
<a ng-href="http://www.gravatar.com/avatar/{{hash}}"/>

Or maybe it won't -- amusingly(?), the Angular docs get it wrong.  Here's a snippet from "view source" of http://docs.angularjs.org/api/ng.directive:ngHref:

            <li class="nav-header section" ng-show="module.directives">
              <a href="{{URL.directive}}" class="guide">directive</a>
            </li>
            <li ng-repeat="page in module.directives" ng-class="navClass(page)">
              <a href="{{page.url}}" tabindex="2">{{page.shortName}}</a>
            </li>

On the other hand, ctrl-click on those links open in a new tab, for me.  (Windows 7, Chrome 28.0.1500.72 m).

-- Larry

Owen M

unread,
Jul 30, 2013, 3:13:52 PM7/30/13
to ang...@googlegroups.com
Turns out to be a Chrome thing. When command-clicking anchor links for the same page in Chrome, it doesn't open a new tab/window. You can test it easily here:

In FF/Safari the command click link works as expected, opening link in new tabs.

I ended up solving this by moving to HTML5 style links, which I wanted to do eventually anyway.
Reply all
Reply to author
Forward
0 new messages