Jump to content
xisto Community
Sign in to follow this  
Jens_L

Downloads With Javascript?

Recommended Posts

You can disable right clicking with Javascript. There are thousands of scripts avaiblable online so there no need to repeat it here. Just search "disable right click" and "javascript" with your favourte search engine. Basically how it works is that it catches all right clicks on the page are and displays a message for example. The idea is just to override the browsers default behaviour (opening the right click menu). You could just have the script doing nothing.However this system is rather fragile. Anyone knowing even slightest of scripting and website design realizes that you implemented the feature with Javascript and by just simply turning off Javascript can do "Save as...".Anyways you can do the thing with Javascipt all though I don't see much point.

Share this post


Link to post
Share on other sites

Thanks but i don't need to disable the right click.When you left-click a link that is to a mp3, the browser opens it. I want to make the browser download it, or ask the user if he wants to download it.Is there a script for this?

Share this post


Link to post
Share on other sites

Create 2 buttons/images. One for listening, the other for download. Use the javascript below with the download button.

For IE 4 +

document.execCommand('SaveAs',null,'filename.html')ordocument.execCommand('SaveAs',null,'filename.html')

Example code to use in document:
<a href="/testmp3.mp3"><img src="/listen.gif" alt="Listen to the mp3!" /></a><a href="#" onclick="document.execCommand('SaveAs')"><img src="/download.gif" alt="Download the mp3!" /></a>
I guess that can work. I think you can put an event handler on an anchor tag. Modify it to your liking.

Example javascript code came from http://forums.xisto.com/no_longer_exists/
Edited by minnieadkins (see edit history)

Share this post


Link to post
Share on other sites

I check the execCommand at

 

[url = [url="http://forums.xisto.com/no_longer_exists/

 

 

 

and the Save As Command Identifier only

saves the current Web page to a file.

 

I want to save the mp3 file not the webpage.

 

This is hard...

Share this post


Link to post
Share on other sites

You're right. I didn't notice that it only saved the .html document. I tried downloading an image in a test document and it came up with a javascript error.

document.image1.exeCommand(....

 

Apparently document is the only object that supports that function, and it's only for IE. So even if it worked

it would be a bad way to do it.

 

I did a little looking and found this thread

https://www.daniweb.com/digital-media/ui-ux-design/threads/39611/clicked-link-countdown

 

There's a PHP solution on post # 24 of the thread. There doesn't seem to be a javascript, or simple solution. Sorry for giving you bad javascript. I didn't test it, I just assumed it was a standard function. Something as simple as 'save as' should be easier to implement.

 

-Good luck

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.