Click to See Complete Forum and Search --> : invoking 'save target as' with left click


merdolator
09-24-2003, 02:28 PM
i may be using the wrong code here, but it seems to work all except that it only recognizes .html and .txt formats to save as... thats fine if it is text or html... but what its it is an .exe or an .mp3?

here's my code:
(in the <head>section)

<script>

function saveAsMe (filename)
{
document.execCommand('SaveAs',null,filename)
}
</script>



(in the <body>section)

<form name="TheForm">
<input type=button value="Save As" onclick="saveAsMe('replacethiswiththefileofyourchoice.exe');">
</form>


reasons for trying to accomplish this:
1) sometimes peoples browsers are set up to run or play (.exe and .mp3 files respectively) instead of downloading.
2) would like to be able to use this in conjunction with disable right click script.
3) attempting test for use with .swf files where left click for link is only option (right click gives flash player info)

if someone could direct me in the right way i would be most thankful. i am not sure i am using the correct objects to invoke. maybe its not a document but a target file, but i am not sure how to reference that properly.

Jona
09-24-2003, 02:36 PM
First of all, there is no reason for a no-right-click script, because it only frustrates users--it is easy to get past and does not protect your images.

Also, you can only use the function you have posted for ASCII files--not binary files. If you could do this with binary files (.mp3 or .exe, for example), you could force people to download viruses against their wishes. Instead, you should use HTTP Requests with a server-side language to do this.

[J]ona

merdolator
09-24-2003, 02:49 PM
ok [J]

i got your points about right click disable and such, but my question is still open.

should i try using a php script or something instead for users such as yourself that are afraid of virii? (which i have NO intentions of transferring) and is it even possible to invoke this kind of function with javascript?

for instance, if i want to enable users to download mp3s from a music oriented site without their browsers choosing for them that they will play it... offering a save as function would be great. consider modem users that have this set up thru their browsers to PLAY instead of save to lacal drive and play. a 3 meg file trying to stream via WMP is going to freeze things up and stutter playback IF it even plays back at all.

i guess i just need to know if its even possible to invoke right click fucntions thru left clicking.

thanks for your time and input. :)

pyro
09-24-2003, 02:53 PM
Take a look at http://www.infinitypages.com/research/download.htm

merdolator
09-24-2003, 03:01 PM
boo-yah PyRo~~

so... .php does indeed seem to be the way to go.
i have been looking for this solution for a couple days.
i am going to test it out on .mp3 files and see whats the hap.

thanks for the quickness of your suggestion/help.:cool:

pyro
09-24-2003, 03:03 PM
You are very welcome... As always, I was very happy to help... :)