473,756 Members | 6,028 Online
Bytes | Software Development & Data Engineering Community
+ 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 3806
On Sat, 24 Jan 2004 09:40:14 -0500, Robert Oschler
<no_replies@fak e_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.******@blueyo nder.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@fak e_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 .somethingoffbe at 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@fak e_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*****@agrico reunited.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
5075
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 , ot the left are 2 columns of clickable icons, Pointer, PictureBox, Label, Textbox, etc Which of these do I use to make an ON or ENABLE sending data bits and a STOP, or Disable data bits. thanks
4
2624
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
5033
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 structure of each event is: Event div Left-floated image Event header div
20
5218
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 designed the query in the design view of Access. The code in question is below, I apologise for the length of the SQL statement Dim SqlComText As String = "SELECT TblCentreSession.ID, TblCentreSession.Session AS , TblSession.SessionYear AS...
16
11583
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, image N, the panel N becomes visible and all the other invisible.
11
5173
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 below <p> and <ul>. Can someone suggest a method using css to accomplish this? I have succeeded in doing this in IE6 but I'd also like to know if there's a method to achive this goal that will have a similar visual look in other modern browsers....
19
2445
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; //every class may have this statement self.hello = function() {
7
7393
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 problem is i don't know how to make it go behind all the other divs. can anyone help? These are the .div's i have created and .div3 is the .div i have been using to try and become the background .div0 { background-color:black; color: purple;...
2
18297
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: def __init__(self, canvas, xy, color, change): self.canvas = canvas self.id = self.canvas.create_rectangle(-10-abs(change),
3
2518
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 the page to select an option from my user control. Can I make this user control floatable so that as the user scrolls down the page the user control moves down also?
0
9212
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9973
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9779
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8645
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6473
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5069
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5247
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3742
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 we have to send another system
2
3276
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.