Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Downloads With Javascript?
Jens_L
post Mar 26 2006, 02:50 PM
Post #1


Newbie [ Level 1 ]
Group Icon

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
Go to the top of the page
 
+Quote Post
Hercco
post Mar 26 2006, 03:52 PM
Post #2


Super Member
Group Icon

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.
Go to the top of the page
 
+Quote Post
Jens_L
post Mar 28 2006, 10:46 AM
Post #3


Newbie [ Level 1 ]
Group Icon

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?
Go to the top of the page
 
+Quote Post
minnieadkins
post Mar 29 2006, 08:47 PM
Post #4


Premium Member
Group Icon

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
Go to the top of the page
 
+Quote Post
Jens_L
post Mar 31 2006, 09:42 AM
Post #5


Newbie [ Level 1 ]
Group Icon

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
Go to the top of the page
 
+Quote Post
Jens_L
post Mar 31 2006, 09:56 AM
Post #6


Newbie [ Level 1 ]
Group Icon

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...
Go to the top of the page
 
+Quote Post
minnieadkins
post Mar 31 2006, 02:33 PM
Post #7


Premium Member
Group Icon

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
Go to the top of the page
 
+Quote Post
Jens_L
post Apr 3 2006, 10:54 AM
Post #8


Newbie [ Level 1 ]
Group Icon

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!
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Getting Screen Resolution using Javascript.(8)
  2. How To Create A Popup Window With Javascript?(19)
  3. javascript vs java(12)
  4. Javascript: Disable Mouse Right-click In Browser(16)
  5. Best Way To Learn Javascript(9)
  6. Javascript: Text To Texbox And Back To Text(2)
  7. Unobtrusive Javascript Image Rollovers(0)
  8. Dynamicdrive: Good Site For JavaScript Codes(5)
  9. Javascript: Simple Slidedown Menu(2)
  10. JavaScript: Simple Dropdown Menu(1)
  11. Calling Of Functions Between Mulitple External Javascript Files(2)
  12. Javascript: Browser Detection Script(0)
  13. JavaScript: Hide And Show Any Element With CSS(5)
  14. Ever Needs To Find Out A Table Height Or With With JavaScript(2)
  15. Create And Import JavaScript Modules For A Large Script(2)
  1. Vertical Marquee Using JavaScript(0)
  2. JavaScript Frames & Querystring(4)
  3. JavaScript Off Redirect Script(2)
  4. I Need Help With Javascript.(7)
  5. Problems With Dynamically Loading Javascript(2)
  6. Add Text To Textarea(6)
  7. Javascript Question(4)
  8. Javascript: How Do I Create Embedded Pop-up Windows?(7)
  9. Problem With Javascript Alert();(9)
  10. Include Function For Javascript(7)
  11. Fun With Javascript And Forms(2)
  12. Javascript Help Needed : Alert(z) Works Fine But Document.write Not(2)
  13. Javascript Changes Aren't Working.(6)


 



- Lo-Fi Version Time is now: 30th August 2008 - 05:26 PM