开发者

Download a php-linked file in JavaScript

开发者 https://www.devze.com 2022-12-28 08:29 出处:网络
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 windo

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"开发者_开发知识库>'+'<a href="http://www.youtube.com/get_video?video_id='+video_id+'&t='+t+'=" style="padding: 2px">FLV</a></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+

0

精彩评论

暂无评论...
验证码 换一张
取 消