dominoGuru.com

Your Development & Design Resource

Repeat after me: @Functions are NOT for the web...

I won't go too much into this, but I was talking with a very competent developer this afternoon who asked me how I could get a form to pop-up in a new window, print, and then close said pop-up. This is a quick-and-simple trick, and I won't get into the argument on doing this via a CSS for "Print", but just state this: @Functions should NOT be used for functions on the web. This small feat can be achieved with some very low-level JavaScript and some forethought to application architecture - specifically, a view (we'll call it print) with a form formula to use a form (we'll call it printform) for the printing.

From your view, add the following to create a link/action to the view:

printlink := "<a href=\"javascript:void(0);\" onclick=\"window.open('/" + @WebDbName + "/print/" + @Text(@DocumentUniqueID) + "?OpenDocument','mywindow','status=1,width=350,height=150');\">print</a> ;";

Next, in the OnLoad for the printform, add the following two lines:

window.print();
window.close();

And there you have it - when clicked, the selected document will open in a popup window, auto-print, and then close itself!

For those of you interested in a sloppy, quickly-put-together demo, here ya go!

Domino Guru Example: jsprint.zip

- Update -

I had to replace the download of this example - I accidentally enabled local encryption. And, for the record, I did mean that you should refrain from using @Formula for UI functions.


About the author: Chris Toohey

Thought Leadership, Web & Mobile Application Development, Solutions Integration, Technical Writing & Mentoring

A published developer and webmaster of dominoGuru.com, Chris Toohey specializes in platform application development, solutions integration, and evangelism of platform capabilities and best practices.



More from dominoGuru.com


dominoGuru.com is powered by IBM Notes Domino XPages & hosted by Prominic.NET

Contact Us

Use our Contact / Feedback form or one of these email addresses:

Creative Commons License

Except where otherwise noted, dominoGuru.com by Chris Toohey is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.