用于动态内容的 jQuery 文件另存为对话框
我有一个通过 jquery ajax 调用的 servlet。然后使用 XSL 转换生成的 XML 并显示在屏幕上。现在,要求是打印此内容或将其保存到本地计算机。打印部分工作正常,但我卡在“另存为”部分。我如何使用 jquery/javascript 来做到这一点?我使用的是IE8/XP。
我尝试过
document.execCommand('SaveAs');
单击按钮,但在 IE8 中似乎不起作用。它显示了我在此之前输入的警报,但没有弹出对话框。这里出了什么问题?
I've a servlet that is invoked via jquery ajax. The resulting XML is then transformed using XSL and displayed on screen. Now, the requirement is to either print or save this content to the local machine. The print portion is working fine but I'm stuck at the Save As part. How do I do this using jquery/javascript? I'm using IE8/XP.
I tried
document.execCommand('SaveAs');
on button click but it doesn't seem to work in IE8. It shows the alerts I put in till that point, but doesn't bring up the dialog box. What's going wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您可以使用服务器端代码而不是 javascript 来完成此操作,请设置 content-disposition 标头:
If you can do this using server-side code instead of javascript then set the content-disposition header: