javascript - How do I open a Save As Dialog on a windows machine from a Chrome Extension? - Stack Overflow

Is it possible using Javascript and Html to open a Save As Dialog from a chrome extension on a Windows

Is it possible using Javascript and Html to open a Save As Dialog from a chrome extension on a Windows OS machine?

I have tried the following without luck:

  1. The chrome extension's fileBrowserHandler - It works only on Chrome OS
  2. HTML5 input with type= file - It opens the Open dialog but not save
  3. Anchor tag with download attribute (Save) - It downloads the file directly to the browser's download setting. If the browser's setting Ask Where to save the file is set, it opens the Save dialog. Is there a way to force the browser setting programatically from the chrome extension?

Please let me know if there are any other ways to get around this. Any help would be appreciated. Thanks!

Is it possible using Javascript and Html to open a Save As Dialog from a chrome extension on a Windows OS machine?

I have tried the following without luck:

  1. The chrome extension's fileBrowserHandler - It works only on Chrome OS
  2. HTML5 input with type= file - It opens the Open dialog but not save
  3. Anchor tag with download attribute (Save) - It downloads the file directly to the browser's download setting. If the browser's setting Ask Where to save the file is set, it opens the Save dialog. Is there a way to force the browser setting programatically from the chrome extension?

Please let me know if there are any other ways to get around this. Any help would be appreciated. Thanks!

Share Improve this question asked Jun 1, 2016 at 16:09 RachRach 1111 silver badge9 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

To force the Save Dialog from a chrome extension, use chrome extension's download api and set the saveAs options flag to true. Something like this:

chrome.downloads.download({
    url: window.location.href + '/' + fileName,
    filename: fileName,
    saveAs: true
}, function (downloadId) {
    console.log(downloadId);
});

Try using the FileSaver HTML5 polyfill. It allows you to save anything to a file from JavaScript:

var blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
saveAs(blob, "hello world.txt");

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745189248a4615784.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信