用于动态内容的 jQuery 文件另存为对话框

发布于 2024-09-04 07:54:53 字数 285 浏览 2 评论 0原文

我有一个通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你的往事 2024-09-11 07:54:53

如果您可以使用服务器端代码而不是 javascript 来完成此操作,请设置 content-disposition 标头:

Content-Disposition: attachment

If you can do this using server-side code instead of javascript then set the content-disposition header:

Content-Disposition: attachment
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文