将文本内容写入新窗口(或将内容类型从 html 更改为文本)?
如何准备一个方便用户保存的文本内容?
document.write("this text must be saved")
几乎可以完成工作,但是页面内容被浏览器视为 html,并将保存为 html
。我可以将其更改为 text/plain
吗?
我知道我可以使用“data:”uri 生成它,但是无法指定默认文件名。
谢谢。
How to prepare a text content to be readily saved by the user?
document.write("this text must be saved")
almost does the work, but the content of the page is perceived by the browsers as html, and will be saved as html
. Can I change it to text/plain
?
I know I can generate it with "data:" uri, but then there is no way to specify the default file name.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你尝试过吗
?虽然我不太明白当人们尝试保存时这如何建议文件名。您似乎在这里绘制了新的(且非常不明确的)领域。
have you tried to do
? Though I don't really understand how this suggests a file name when one tries to save. You're charting new (and very under-specified) territory here it seems.
将此标头添加到响应中:
Content-Type: text/plain
Add this header to the response:
Content-Type: text/plain
这可以解决问题
希望有帮助。
this will do the trick
hope it helps.