Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

onqun

macrumors regular
Original poster
Oct 13, 2006
100
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
 
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.
 
it happens in the page it gives link to the file so that you can download
 
it happens in the page it gives link to the file so that you can download

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.
 
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!
 
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 :/
 
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 :/

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...
 
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?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.