0

I have a virtual path 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?

Null Pointer
  • 9,089
  • 26
  • 73
  • 118
  • Look at http://stackoverflow.com/questions/210643/in-javascript-can-i-make-a-click-event-fire-programmatically-for-a-file-input –  Jan 27 '12 at 20:55

1 Answers1

2

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);
mattsven
  • 22,305
  • 11
  • 68
  • 104