Pop up screen when the user clicks to download

Discussion in 'Web Design and Development' started by onqun, Dec 2, 2009.

  1. onqun macrumors member

    Joined:
    Oct 13, 2006
    #1
    Hello I want to add something to my web site. when the user clicks to download. i want to see a pop up screen which says your download has started.

    <script type="text/javascript">
    function show_alert()
    {
    alert("Your Download Started!");
    }
    </script>

    <input type="button" onclick="show_alert()" onclick="get value="Download" />

    I dont get where should i put the download link
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    Does the download happen from that page, or does it load another page to do the actual download? Essentially, need to know how you're currently initiating the download.
     
  3. onqun thread starter macrumors member

    Joined:
    Oct 13, 2006
    #3
    it happens in the page it gives link to the file so that you can download
     
  4. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #4
    Well, then the download doesn't truly start until after it goes to that link. Popping up an alert will keep the download from starting. You can use PHP to get a download going (see readfile) on a page then also have some JavaScript doing a pop-up if you really want to, but it's simple unnecessary. The PHP method is similar to what SourceForge uses on their download pages (they also use AJAX) where they have a message saying the file will download in a moment.
     
  5. Darth.Titan macrumors 68030

    Darth.Titan

    Joined:
    Oct 31, 2007
    Location:
    Austin, TX
    #5
    With the script you wrote, try this. It worked for me.
    Code:
    <a href="path/to/download.file" onclick="show_alert();">Download Here</a>
    I tested in Safari and Firefox. I click the link, the alert appears, then the download starts.

    Like angelwatt said it seems kinda pointless, but whatever floats your boat!
     
  6. onqun thread starter macrumors member

    Joined:
    Oct 13, 2006
    #6
    My dear friend I made the code like this
    <a href="files.me.com/ongun/b4sll8" onclick="show_alert();"><input name="Download" type="button" value="Download" /></a>

    It does not download anything for me :/
     
  7. Darth.Titan macrumors 68030

    Darth.Titan

    Joined:
    Oct 31, 2007
    Location:
    Austin, TX
    #7
    Of course that doesn't work. You can't wrap a button in a link tag. You'll notice in my example I used a text link.

    If you must have a button, you can use some css to style the link to look more "button like", or try this:
    Code:
    <input type="button" name="download" value="Download" onclick="show_alert(); window.location='Tryst.dmg';" />
    Bear in mind that:
    • The download actually starts after the user clicks 'OK', so you might want to adjust the wording of your alert.
    • If the user has javascript disabled, they won't be able to download using your button.
    More trouble than it's worth if you ask me...
     
  8. alexk82 macrumors regular

    Joined:
    Nov 30, 2009
    Location:
    East Coast
    #8
    huh

    if you are downloading from a browser doesn't a popup show up regardless ie where to save or a progress bar? Why do you need something extra indicating that something is downloading?
     

Share This Page