|
|
|
|
![]() ![]() |
Mar 26 2006, 02:50 PM
Post
#1
|
|
|
Newbie [ Level 1 ] Group: Members Posts: 9 Joined: 24-November 05 Member No.: 9,796 |
Hi!
I want to let people download .mp3's. But i don't want them tio have to right-click and "Save as". Is there a way with Java Script? Cheers!' Jens |
|
|
|
Mar 26 2006, 03:52 PM
Post
#2
|
|
|
Super Member Group: Members Posts: 595 Joined: 4-September 04 Member No.: 228 |
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. |
|
|
|
Mar 28 2006, 10:46 AM
Post
#3
|
|
|
Newbie [ Level 1 ] Group: Members Posts: 9 Joined: 24-November 05 Member No.: 9,796 |
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? |
|
|
|
Mar 29 2006, 08:47 PM
Post
#4
|
|
|
Premium Member Group: Members Posts: 292 Joined: 15-December 04 Member No.: 1,768 |
Create 2 buttons/images. One for listening, the other for download. Use the javascript below with the download button.
For IE 4 + CODE document.execCommand('SaveAs',null,'filename.html') or document.execCommand('SaveAs',null,'filename.html') Example code to use in document: CODE <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://faqts.com/knowledge_base/view.phtml/aid/1829/fid/126 This post has been edited by minnieadkins: Mar 29 2006, 08:47 PM |
|
|
|
Mar 31 2006, 09:42 AM
Post
#5
|
|
|
Newbie [ Level 1 ] Group: Members Posts: 9 Joined: 24-November 05 Member No.: 9,796 |
Thanks!
Now I just need to find a way for ma os x and Mozilla But thanks a LOT!!! / jens |
|
|
|
Mar 31 2006, 09:56 AM
Post
#6
|
|
|
Newbie [ Level 1 ] Group: Members Posts: 9 Joined: 24-November 05 Member No.: 9,796 |
I check the execCommand at
[url = http://msdn.microsoft.com/library/default....execcommand.asp 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... |
|
|
|
Mar 31 2006, 02:33 PM
Post
#7
|
|
|
Premium Member Group: Members Posts: 292 Joined: 15-December 04 Member No.: 1,768 |
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 http://www.daniweb.com/techtalkforums/next...hread39611.html 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 |
|
|
|
Apr 3 2006, 10:54 AM
Post
#8
|
|
|
Newbie [ Level 1 ] Group: Members Posts: 9 Joined: 24-November 05 Member No.: 9,796 |
Thanks!
I checked to forum out. Will try to put that PHP-code into action. Hope it works! But the idea of just zipping them is not bad, very easy... Cheers! |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 30th August 2008 - 05:26 PM |