开发者

Save File Dialog Box in Jquery

开发者 https://www.devze.com 2023-02-20 22:55 出处:网络
I have a virtual path开发者_Python百科 to a .wav file. I stored that value in ahidden field. Now when clicking a button i want to show a save dialog box for that virtual path .

I have a virtual path开发者_Python百科 to a .wav file. I stored that value in a hidden field. Now when clicking a button i want to show a save dialog box for that virtual path .

i tried this

    window.open(path, "", "");

But it opens file in media player .I just want to show save dialog so that u ser can select a place to store that file. Is it possible using jquery?


HTML5 introduces a new attribute, download, that allows you to do this. Here's an example with an anchor tag:

<!-- On click opens a 'Save Dialog' for the href specified, and uses the filename specified in the download tag. -->
<a href="http://example.com/path/to/my/file.txt" download="file.txt" />

Triggering the download using JavaScript:

var clickEvent = document.createEvent("MouseEvent");
clickEvent.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); 
document.getElementById("anchor").dispatchEvent(clickEvent);
0

精彩评论

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