Prompt browser download dialogue box - javascript

Normal: download
The reason I can't do this is it's on a Wordpress installation with a plugin (wpaudio) which turns every mp3 filein the code into a mini player which when clicked streams the file. So that link above would appear as a link, with a play button beside it, when clicked would stream the file, and not prompt the download dialogue box. With 99% of the mp3 files on this site that's exactly what is needed.
However for one file, I need to enable the user to click the linked word download, and get the save or open dialogue box, along with subsequent progress bar (if enabled in his browser preferences). PHP or Javascript is fine, either will do, anybody know how to get that working?

According to the plugin site you linked to:
Convert all mp3 links
To turn every mp3 link on your blog into a player, select Convert all mp3 links in the WPaudio settings.
Convert some mp3 links
For any mp3 link you'd like to convert to a player, add the wpaudio class like this:
Artist - Song
So, you probably just don't want to have to go give every link that class right? So, use JavaScript to do it. Give the links you don't want converted a class of no-wpaudio or something, and use JavaScript to add the class to all the links without the no-wpaudio class. Hopefully you are using jQuery:
$("a[href$='.mp3']:not(.no-wpaudio)").addClass("wpaudio");
If not, what a pain, but it can be done. Let me know if you want the non-jQuery code.

Related

How to use Javascript to create custom download process and open file in Chrome?

i am developing a website, in our website we have a Video player, and a Download button. When user click to it, it will download the video to user machine.
Usually this can be done if user right click and choose Save Video as. Then a native browser dialog open, where user can choose destination and file name, then click save. After that in the bottom of the browser there will be a widget to show progress, and user can click to open after it finishes downloading
Now my question is it possible if we create a similiar functional widget but in the website. So basically after user clicking Download. This modal will appear in the bottom left of the page
Then after downloading is finished, it will change to
So to sum up the requirement for this
1/ Trigger download automatically by JS without right click and choose Save video as
2/ Showing a custom progress of downloading
3/ When downloading is finished, there is a custom button, where user can click to Open
4/ [Optional] Hide the native progress/click to open widget of the browser
So these requirement i still not sure which one is possible and which one is not, so hopefully if someone can give me a direction, thanks

how to determine if the user click this download popup? [duplicate]

I got a webpage where members can download different kind of files on. I wan't to get information about which files and how many times each member have downloaded. when the user want to download a file he get browser pop-up where he gets 3 choises: "Open", "save" and "Cancel".(file dialog box in browser). i want to update the download status only if open/save button is clicked
Is there a way to detect which button was clicked on "save/open/cancel" dialog?
You can't know that. Some browsers even start the download before the user decides what to do with the file. But perhaps you can get your webserver to log if the download has been completed. That's probably the most reliable result you can get.
There is no way to know which button was clicked.
I dont think you can. The site just streams the file to the browser. What the user does
with the file is not known by the website as there is no more server side
interaction.

Give an option to download pdf OR open in browser

I'm pretty sure this isn't possible but thought I'd check with you guys.
I've just had a bizarre query from a client who wants to know if it's possible to give the user the option to either download a pdf or open it in their browser.
They have a thumbnail for the PDF. Single click to open it in the browser or double click to download it. I know I can catch the single or double click with jQuery. I just want to know if it's possible to force the behaviour of the link.
Thanks
This is possible, if for example you are using PHP you can create 2 methods, once will be a simple direct link to the pdf file (if a customer has adobe reader then it will open the pdf in the browser otherwise it will force a download), the other method would always force a download.
You can find a PHP force file download example here: How to force download of a file?

How can I get my PDF to open in Adobe Reader by clicking a link in my website?

I am really having some problems in that I want my visitors to open a certain PDF from a link on my site, however, I can get it to display on a separate tab next to my website, but what I would really like is for it to be forced to open in Adobe Reader.
Is this possible? Has anyone managed to do this?
I have my links set up, they open in a separate tab, but I just feel its more professional if it were to open in Adobe Reader.
Ive been looking for the same thing, and the answer is very simple : add download to your a href code : < a href="document.pdf" download>
It prompts a box which asks you if you want to save or just open the document
Normally the browser will detect that the link with holds a .pdf, and it will open up the PDF in the browsers viewer, and I have seen this in just about all browsers. Then you will be able to use the given functions like size, print, and save.

Download a php-linked file in JavaScript

I have a big problem. I've made a simple Google Chrome plugin (based on the old Youtube Video Downloader) but I have some problems with it. The first problem is that it won't pop up a new save window on click, but opens a new page with the video in the default Chrome player. The second is, that when the user clicks right click-save, they won't get the video name but a standardized name.
Is there any way to make a file save dialog with a specified file save name?
EDIT:
The link is automatically generated based on the Youtube video link, this way:
document.getElementById('watch-description-body').innerHTML+='<button id="download-youtube-video-button" data-button-listener="" data-tooltip-timer="300" class="yt-uix-button yt-uix-tooltip" data-tooltip="Right-click and click Save Link As... to download" type="button">'+'FLV</button>' ;
So basically it ads a button to the existing page, with a specified link:
http://www.youtube.com/get_video?video_id='+video_id+'&t='+t+'=
Where video_id is the Video ID number, and t is the time the player was stopped.
1) To 'force' a download, rather than a page load you will need to deliver a Content-Disposition: attachment HTTP header.
Or you could just use the new HTML5 property download in the anchor tag of your html.
The code will look something like
<a download href="path/to/the/download/file"> Clicking on this link will force download the file</a>
It works on firefox and chrome latest version. It also seems to work IE6+

Categories

Resources