OHICA wrote:
<a href="/muzak/wong.mp3"> as link
what can I do to this in javascript to make it behave?
Nothing if you are talking about *client-side* J(ava)Script. JS is but
a language, a tool. It can use core objects, host objects and user
objects. Unfortunately, there is no object that does what you are
looking for _and_ is available in all user agents.
So to be sure, you need to reference a server-side script (I recommend
PHP instead of JS) that takes the filename as parameter and serves the
respective file with a different MIME content type.
<OT>
Content-Type: application/octet-stream usually triggers a file download,
the correct Content-Type (audio/mpeg) will trigger either a file
download or the configured plugin to download (and play) it (which is
what you have experienced, others may have not!). I have read about a
better way than app/8-stream but alas I forgot it. (If anyone can tell,
please do so.)
For .mp3 files, a server-side script could return a playlist (.m3u is
common) as well. I do not know for sure, but that could allow for
streamed downloads. (CMIIW)
For example:
[<a href="foobar.mp3">Play</a>]
[<a href="playlist?file=foobar.mp3">Play with playlist</a>]
[<a href="download?file=foobar.mp3">Download</a>]
You need to configure the web server to serve .mp3 files as audio/mpeg.
For NCSA-httpd compatibles using httpd.conf or .htaccess, like the
Apache HTTP Server:
AddType audio/mpeg .mp3
Untested download.php:
<?php
if (isset($HTTP_GET_VARS['file']))
{
header('Content-Type: application/octet-stream');
include($HTTP_GET_VARS['file']);
}
?>
</OT>
HTH
PointedEars