473,497 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Make left-click cause an audio file download instead of stream?

Hello,

I have a web site that has an audio file on it that I make available for
download. Right now I'm using the "right-click/save-as" approach. This is
because left-clicking the link to the audio file initiates client-side
streaming/playing of the audio file. Is there a way with Javascript to make
a left-click trigger a download of the file instead?

BTW, I don't want to have convert the mp3 file to winzip to make this
happen, because some people don't have an unzip utility.

thx

--
Robert Oschler
http://www.dog-images.com -- Devoted to providing free info on the health,
nutrition, and training of dogs.

Jul 20 '05 #1
4 3781
On Sat, 24 Jan 2004 09:40:14 -0500, Robert Oschler
<no_replies@fake_email_address.invalid> wrote:
I have a web site that has an audio file on it that I make available for
download. Right now I'm using the "right-click/save-as" approach. This
is because left-clicking the link to the audio file initiates client-
side streaming/playing of the audio file. Is there a way with
Javascript to make a left-click trigger a download of the file instead?


No[1].

If you can use a server-side script, you can send the file with the
application/octet-stream content type, which will force the "Save as"
dialog. However, I don't know the specifics, so you'll have to ask in a
newsgroup dedicated to that language.

Mike

[1] Even if there was, it wouldn't be compatible with all browsers.

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #2
Michael Winter wrote:
On Sat, 24 Jan 2004 09:40:14 -0500, Robert Oschler
<no_replies@fake_email_address.invalid> wrote:
[...] left-clicking the link to the audio file initiates
client-
side streaming/playing of the audio file. Is there a way with
Javascript to make a left-click trigger a download of the file instead?

No[1].

If you can use a server-side script, you can send the file with the
application/octet-stream content type, which will force the "Save as"
dialog. [...]


And, AIUI, even this might not work in some browsers because those
browsers ignore the Content-type header and use the file's extension to
determine how to treat it. And it appears some browsers can be
configured to use either content-type or file extension.

Stephen
Jul 20 '05 #3
Robert Oschler hu kiteb:
Hello,

I have a web site that has an audio file on it that I make available
for download. Right now I'm using the "right-click/save-as"
approach. This is because left-clicking the link to the audio file
initiates client-side streaming/playing of the audio file. Is there
a way with Javascript to make a left-click trigger a download of the
file instead?

BTW, I don't want to have convert the mp3 file to winzip to make this
happen, because some people don't have an unzip utility.


Javascript can't force a browser to handle a file format in a particular
manner. That is usually left to the default settings of the browser,
modified by whatever applications or user settings have been changed.

I guess if you rename teh file extension as .somethingoffbeat then the
default action would be to ask to download, but that seems kind of
awkward.
--
--
Fabian
Visit my website often and for long periods!
http://www.lajzar.co.uk

Jul 20 '05 #4
Stephen wrote:
Michael Winter wrote:
On Sat, 24 Jan 2004 09:40:14 -0500, Robert Oschler
<no_replies@fake_email_address.invalid> wrote:
[...] left-clicking the link to the audio file initiates
client-
side streaming/playing of the audio file. Is there a way with
Javascript to make a left-click trigger a download of the file instead?

No[1].

If you can use a server-side script, you can send the file with the
application/octet-stream content type, which will force the "Save as"
dialog. [...]


And, AIUI, even this might not work in some browsers because those
browsers ignore the Content-type header and use the file's extension to
determine how to treat it. And it appears some browsers can be
configured to use either content-type or file extension.

Stephen


Adding the following headers from the server (as an example) seems to work
reliably in all browsers I've tested:

Content-Disposition: attachment; filename="file.xls"
Content-type: application/vnd.ms-excel

Even IE on a Windows system with Excel installed prompts to download the file,
rather then loading it in-place in IE.

Adding the following headers from the server ensures most browser will force a
download of it:

Content-Disposition: attachment; filename="file.mp3"
Content-type: application/octet-stream

--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
5058
by: EN | last post by:
Hi, I want to put a bmp of a toggle switch leaning to the left, the off position. With a painter prgm, flip the left toggle , lean right, for ON or Start position. How do I do this? With VB 6 ,...
4
2598
by: Daniele petracca | last post by:
<SCRIPT TYPE="text/javascript"> if (screen.width==1024) { distanza=100; sinistra=100; } else { distanza=10; sinistra=10; } document.write(screen.width);
0
5018
by: Charles Blaquière | last post by:
While noodling around, looking for a good layout for an "events calendar" page, I came upon a problem that has me stymied. Have a look at http://kpuc.org/events/upcoming-2.html . The basic...
20
5164
by: Neil Robbins | last post by:
I am trying to execute a make table query in my vb.net program. The db that I am accessing is an Access 2000 format db. The SQL code that I am using has been cut and pasted from the SQL View having...
16
11489
by: Miguel Dias Moura | last post by:
Hello, i have 5 panels in an ASP.net / VB page. The panel 1 is visible the other 4 are NOT visible. I also have 5 images: image 1, image 2, ..., image5. When i click one of the images,...
11
5152
by: namenotgivenhere | last post by:
My design goal is to make the white space above and below <p> and <ul> equal to the height of my font. The first step to achieving this I believe is to have an equal amount of white space above or...
19
2408
by: zzw8206262001 | last post by:
Hi,I find a way to make javescript more like c++ or pyhon There is the sample code: function Father(self) //every contructor may have "self" argument { self=self?self:this; ...
7
7363
by: Ryaby21 | last post by:
Please help! i have everything set up with my CSS HTML layout and its all good. im using 3 divs at the moment and what i want to to do now is to add a new div with a background for the page. My...
2
18217
TMS
by: TMS | last post by:
Schools over!!! Now its time to play. I would like to learn how to make objects move from one location to the next on a canvas widget. For example: from Tkinter import * class square:...
3
2508
by: =?Utf-8?B?Qw==?= | last post by:
Hi, I have a user control which I use on all my pages. The control is situated on the top of my page (sits on my master page). For some long pages the user has to scroll back up to the top of...
0
6991
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7160
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7196
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7373
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4897
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4583
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1405
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
649
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.