API
@-Formulas
JavaScript
LotusScript
Reg Exp
Web Design
Notes Client
XPages
 
Use Pages To Store JavaScript
If you get some JavaScript working that's generic (like a generic string trim function, for example), then how do you make it reusable?

Well, the one obvious thought is to put it into a subform and put it into the JSHeader on the subform. That works and is effective, but there's another option that you might want to consider.

You can create a page design element. Name the page whatever you want, but make sure it ends in .js (yes, a period in the name of the design element). If the name of the page is unique to the database (and with an extension like that, it should be) you can reference that page without the ?OpenPage at the end of the URL. In addition, this means that you can reference the page in other applications (remote databases or the same database) as JavaScript. To refer to this as actual JavaScript, you can put pass-through html on another form in this format:

<script language="JavaScript" src="/mynsf.nsf/mypage.js"></script>

That needs to be the format of a src parameter so it's fortunate that you don't need the ?OpenPage to reference that page.

When designing the page, you will want to make sure you enable the page property "Treat page contents as HTML". Otherwise Domino will put in <br> tags and other HTML that you don't want. You just want the JavaScript functions. Also, note that you should not have <script> tags (either opening or closing) on the page -- just the functions. On the form which is loading this page will be the opening and closing <script> tags. That's the specifications on external JavaScript.

With that "Treat page contents as HTML" enabled, you can go ahead and do whatever formatting you want on the page. For example, you can color-code all you want. I've noticed that the JS Header doesn't color-code the keyword var when it's used to define a variable -- you could make that blue in the page if you want. You could also use different font sizes and styles for different parts of the function if you want. It will all be just passed as plain text (HTML) to the browser.