2011-03-29 103 views
0

我有一個.wav文件的虛擬路徑。我將該值存儲在隱藏字段中。現在當點擊一個按鈕時,我想顯示該虛擬路徑的保存對話框。在Jquery中保存文件對話框

我想這

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

但它打開文件的媒體播放器。我只是想表明保存對話框好讓你SER可以選擇存儲文件的地方。是否有可能使用jQuery?

+0

看http://stackoverflow.com/questions/210643/in-javascript-can-i-make -a-click-event-fire-programmatically-for-a-file-input – 2012-01-27 20:55:04

回答

1

HTML5引入了一個新屬性download,它允許您執行此操作。下面是用錨標記示例:

<!-- 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" /> 

觸發使用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); 
+1

@trejder已更新。 – mattsven 2014-11-11 13:39:27