Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open a new window on click with ember

Tags:

ember.js

How can I open a new window when the user clicks on a link?

I have tried adding target="_blank" and bindAttr but it doesn't work.

The code that doesn't work:

<a target="_blank" {{action goToSettings href=true}}>App Settings</a>

or

<a {{bindAttr target="_blank"}} {{action goToSettings href=true}}>App Settings</a>

And this is the html output from the first example:

<a target="_blank" href="#/settings" data-ember-action="5">App Settings</a>
like image 526
George Eracleous Avatar asked Dec 21 '12 23:12

George Eracleous


2 Answers

This has been added to LinkView, and therefore is now supported directly in {{link-to}}.

Pull request is at https://github.com/emberjs/ember.js/pull/4718

like image 27
bargar Avatar answered Nov 07 '22 16:11

bargar


You have two choices:

  1. send an action, and in the javascript that handles the action, call window.open(...) to open a new window to a particular URL
  2. Don't use an action and instead make it a static link or if you need to dynamically vary the target URL, use <a target="_blank" {{bindAttr href="yourBoundPropForTheUrl"}}>Click here</a>
like image 192
Luke Melia Avatar answered Nov 07 '22 14:11

Luke Melia