javascript - force save dialog for a video link -


i want create download link video. how can force open save dialog box when link clicked.

<a href="#" onclick="downloadvideo()">download video</a> 

as pekka implied, force file download normal html link sending additional http header. means may need change configuration of web server work.

normally, clicking link won't return content-disposition header; setting how "save file..." dialog box appear. response headers bit like:

http/1.1 200 ok date: sun, 21 aug 2011 11:45:59 gmt server: apache/2.2.14 (ubuntu) content-disposition: attachment; filename=video.m4v; 

without knowing inner workings of application or site, i'd tentatively suggest (for benefit of users javascript switched off) don't use js if possible.

your best bet make change configuration of web server. apache, you'd like:

<filesmatch "\.m4v$">   <ifmodule mod_headers.c>     header set content-disposition "attachment"   </ifmodule> </filesmatch> 

...which make m4v files show "save file..." dialog box. or if application written in php, do:

header('content-disposition: attachment; filename="video.m4v"'); 

this page has bit of javascript (possibly jscript?) use works in internet explorer, not in other browser:

<a href="javascript:void(0);" onclick="document.execcommand('saveas',true,'video.m4v');">download video</a>  

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -