简体   繁体   English

使用Java保存文件对话框

[英]Save File Dialog with Javascript

I would like to ask if there is any lines of code that I can put in a JS file to pop up a file dialog and prompt me to save a txt file that was created? 我想问一下是否可以在JS文件中放入任何代码行以弹出文件对话框,并提示我保存创建的txt文件?

Currently, using ember.js in my project. 目前,在我的项目中使用ember.js。 The sequence of action are clicking a button in the webpage will tigger an action to call a function in one of my js file. 操作顺序是单击网页上的按钮将触发一个操作,以调用我的js文件之一中的函数。

Thanks 谢谢

Because of normal browser security limitations, you cannot use JavaScript to save a file to the desktop from a web browser so in short the answer is no you can't. 由于正常的浏览器安全限制,您不能使用JavaScript从Web浏览器将文件保存到桌面,因此总之,答案是“不能”。

I have made the assumption you are generating text to be saved to a file in the Web Browser. 我假设您正在生成要保存到Web浏览器中的文件的文本。 What you can do is submit that text to your web server and have your web server send the text back as the HTTP response but setting the following HTTP Header... 您可以做的是将该文本提交到您的Web服务器,并让您的Web服务器将文本作为HTTP响应发送回去,但是设置以下HTTP标头...

Content-Disposition: attachment; filename=<file name.ext>

... which will force the Save As dialog, instead of the browser rendering it on screen. ...这将强制“另存为”对话框,而不是浏览器在屏幕上呈现该对话框。

Reference: http://www.jtricks.com/bits/content_disposition.html 参考: http : //www.jtricks.com/bits/content_disposition.html

Hope that helps you... 希望对您有帮助...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM