Patoshi パトシ
Patoshi パトシ

Reputation: 23475

URL to file forces download, how to disable downloading and store this file into a javascript variable in the client side?

I have a url to a .mp3 file and its forcing me to download it when loading it on the client side. Is there a way to disable this forced download and store this mp3 file into a variable so I can load it into my javascript mp3 player?

Upvotes: 0

Views: 374

Answers (1)

Emeeus
Emeeus

Reputation: 5250

You could do something like this:

  <a id="link" href="http://example.com/path/some.mp3">link</a>

  <script> 
    $("#link").on('click', function (e) {
        e.preventDefault();
        var url = $("#link").attr("href");
        var a = new Audio(url);
        a.play();

});
  </script>

Upvotes: 1

Related Questions