最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Open save as dialog on newly opened window - Stack Overflow

programmeradmin2浏览0评论

How in JS/jQuery do I pop open the "Save As" dialog for a newly opened window. Basically I am scraping some data off of a web page. As such I am opening a new window via:

dataWindow = window.open('blank','dataWindow');

I then write the output to the blank window but I want to automatically pop open the "Save As" dialog to save the content of the window to a file (text/csv). How would I do this. I tried:

dataWindow.document.execCommand("saveAs",true,".txt");

but it doesn't seem to do anything.

How in JS/jQuery do I pop open the "Save As" dialog for a newly opened window. Basically I am scraping some data off of a web page. As such I am opening a new window via:

dataWindow = window.open('blank','dataWindow');

I then write the output to the blank window but I want to automatically pop open the "Save As" dialog to save the content of the window to a file (text/csv). How would I do this. I tried:

dataWindow.document.execCommand("saveAs",true,".txt");

but it doesn't seem to do anything.

Share Improve this question asked Dec 15, 2009 at 22:45 GregHGregH 12.9k25 gold badges82 silver badges120 bronze badges 2
  • Don't care if it works in IE...I only need it to work in Firefox – GregH Commented Dec 15, 2009 at 23:10
  • Sorry, I don't get how to send the content-disposition header using JS once the output is sent to the window. – GregH Commented Dec 15, 2009 at 23:27
Add a ment  | 

1 Answer 1

Reset to default 2

execCommand is not an ideal way to do this kind of thing, since it's a pretty browser-specific extension to javascript.

There's a good suggestion in this thread to make a Save As dialog happen by returning a content-disposition header to make the browser think that the content is an attachment.

Edit: This other thread also has some suggestions along the same lines.

发布评论

评论列表(0)

  1. 暂无评论