0

How do I download the pdf file on click which has the following syntax

<a href =   "http://www.pdf995.com/samples/pdf.pdf" download >Click to download!</a>

And the pdf is associated with a model within the <li> item like this

<script type="text/x-handlebars" data-template-name="index">
    <ul>
    {{#each item in model}}
      <li {{action action1}}>{{item}}
        <a href =   "http://www.pdf995.com/samples/pdf.pdf" download >Click to download!</a>
      </li>
    {{/each}}
    </ul>
  </script>

Where as if I place the tag outside the li it works fine and the pdf is downloaded. How do I make it work inside the <li> tag which has an action. Seems like the action is called first always!

Demo

Ajey
  • 7,924
  • 12
  • 62
  • 86

1 Answers1

0

EDIT:

Try this:

http://emberjs.jsbin.com/zifeyihe/7/edit

App.IndexController = Ember.Controller.extend({
  actions: {
    action1: function(item){
      alert(item.color);
      window.document.location.href = item.link;
    }
  }
});

It just redirects to the PDF after alert was shown.

medokin
  • 610
  • 9
  • 21
  • I would want the file to be downloaded on the same page and your fiddle is not working, pls check – Ajey Jun 23 '14 at 13:43
  • I would not want to redirect, I am trying to download the pdf on the same page – Ajey Jun 23 '14 at 13:59
  • This should help: http://stackoverflow.com/questions/3749231/download-file-using-javascript-jquery – medokin Jun 23 '14 at 14:17