2

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?

2
  • What is it exactly that you want to have saved? The HTML itself, the content as XML or maybe even a translation to PDF? Commented Jun 1, 2010 at 22:06
  • Well, the transformed XML displays on the screen. Now the user should have an option to save the current html page on to the local system. The browser's File>Save As menu is not enough. There needs to be a button on the page itself with some appropriate icon, which when clicked, will bring up the Save As dialog of the Windows. Just to add... there's no PDF conversion involved, though it might come later. Commented Jun 2, 2010 at 17:28

1 Answer 1

1

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

Content-Disposition: attachment
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, but wouldn't that bring up the Save As dialog as soon as the servlet is invoked? I thought it would, haven't tried though. In my case, the content first needs to transform and display on the screen as HTML and then on a button click, should bring up the Save As dialog. Please see my comment above in response to Marc's question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.