SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2006
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Javascript File Download

    Hey everyone,

    What I want to do is create a link like this:

    HTML Code:
    <a href="javascript:download('audio.mp3')">Download</a>
    With the function triggering a file download. Is it possible to do something like that in javascript? What would that function look like?

    Thanks
    Matt

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I can only assume you would want:

    Code:
    function download(file) {
    window.location = file;
    }


  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,784
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    A better way to achieve the same thing would be:

    <a href="audio.mp3">Download</a>
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  4. #4
    SitePoint Enthusiast
    Join Date
    Sep 2006
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    neither solution actually triggers the file download, however... just functions as a link to the file. i actually accomplished what i wanted with a modified version of this PHP script:

    http://www.zubrag.com/scripts/download.php

    in case anybody else is interested


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •