开发者

Open save as dialog on newly opened window

开发者 https://www.devze.com 2022-12-14 15:22 出处:网络
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:

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 开发者_StackOverflow社区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.


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

精彩评论

暂无评论...
验证码 换一张
取 消