dominoGuru.com
Your Development & Design Resource
Repeat after me: @Functions are NOT for the web...
10/16/2007 11:02 PM by Chris Toohey
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!
- 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.