PDA

View Full Version : Javascript to Trigger Print/Save Images



KraftyDood
12-14-2006, 03:00 AM
Is it possible to request a print or save operation for an image on the page via Javascript, just as if the user has right-clicked on the image and selected the "Print Image" or "Save Image As" opitons? I want the printer and save-as dialogs to come up.

The only approach for printing an image I have seen is to have javascript open a new browser window containing just the image and triggering a window.print() followed by a window.close() - but this sounds a bit clunky to me.

What I was hoping was that the image object actually had print() and save() methods that could be used from Javascript, but I haven't read anything that supports that hope.

Thanks for any ideas.

KraftyDood
12-15-2006, 07:13 AM
Is no-one going to offer any thoughts on this? I would have expected someone at least to tell me "NO - NOT POSSIBLE" - which is what I am currently thinking.

If what I am looking for is possible, I would really appreciate a push in the right direction.

jscheuer1
12-15-2006, 07:45 AM
Would; "I doubt that it is possible", help? I always hesitate to say no, a thing isn't possible, because one can never be 100% sure of something like that in a case like this. I can say there is no common, widely used, javascript method for that.

For printing you could probably have a button or link that activates an alternate stylesheet that sets the print display property of everything else on the page to 'none' and then prints the page (which in this case would then be just the image). But, how to get the print display back to normal after that without having it possibly interfere with the printing process if that took some time for the user to follow through on . . .

For saving, you could perhaps have a link to the image that has its mime type or something like that set a certain way that would cause most browsers to put up the save/open prompt.

In the end, it would be much easier to just have a pop-up division with or just have instructions as, most folks have this functionality already built into the browser. All you really need to do is instruct those who do not, as yet, know how to use it.

KraftyDood
12-15-2006, 07:37 PM
Thanks for the feedback. I am thinking you are right, and that in the end the way to go is just providing on-screen instructions for printing/saving images for those who don't know how.

Some of our users are very web-challenged, and we get a lot of help-desk calls about really 'basic' stuff. We thinking obvious buttons for printing/saving the image would make it easier for them, but instructions will have to be enough.