簡體   English   中英

是否可以使用javascript在特定目錄中保存諸如.swf,.mp3,.txt等文件,而無需“另存為”提示?

[英]Is it possible to save a file such as .swf, .mp3, .txt, etc. without the “save as” prompt using javascript in a specific directory?

我正在開發一個節點Webkit應用程序。 單擊一個按鈕時,我想下載一個.swf文件,並將其自動保存到特定目錄。 現在,我可以下載它,但是提示“另存為”對話框。 是否可以禁用它並自動保存它? 使用JavaScript可以嗎?

否。否則,惡意網站將能夠覆蓋您計算機上的重要文件

節點Webkit應用程序不是網站,因此可以,您可以使用節點模塊來實現。 例如,使用fs (文件系統):

var fs = require("fs");
fs.writeFile("myfile.txt", "Yes! with nwjs i can do stuff that i'm not allowed to do in browser!", function(err) {
  if(err)console.log(err)
  else console.log("file saved");
});

也許您可以閱讀下載文件的內容並將其通過管道傳輸到所需位置:

fs.createReadStream(source_file_path).pipe(fs.createWriteStream(dest_file_path))

您不受瀏覽器的限制。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM