开发者

Write text content to a new window (or change the type of content from html to text)?

How to prepare a text content to be readily saved by the user?

document.write("this tex开发者_开发知识库t 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.


have you tried to do

document.open('text/plain');
document.write('Save me');

? 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.


Add this header to the response: Content-Type: text/plain


this will do the trick

Response.AddHeader("content-disposition", "attachment; filename=" + fileName);

hope it helps.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜