View member feedback to this tip.
This article is a "counterpoint" to Luke Leonhard's tip, Run a Web agent on any JavaScript event. . Luke demonstrates how you can run (using XML and Microsoft's XMLHTTP ActiveX component) an external agent from any JavaScript event and get results back without a screen refresh.
One of the downsides I noted in Luke's tip is the requirement of having to use a "browser specific" ActiveX component. The method demonstrated here (which I have employed on many applications) is browser agnostic, in that it uses standard Web technologies (providing your browser can support JavaScript and iFrames).
The basic logic is to have a form that contains an iFrame within it and an external process that can execute JavaScript in that iFrame. The iFrame must have some way of grabbing a handle to it (such as an ID), but can be easily set up to be transparent to the user as follows:
Now you can change the style on the div to make it "block" or "none" if you want to see the iFrame while coding and debugging, or eliminate the div completely and simply set the iFrame to a height/width to 0. Then use whatever method you choose to launch the agent by telling the agent to run in the iFrame window:
The agent itself will perform whatever operations you wish and the results sent back from the agent will be placed in the iFrame. Then, using JavaScript methods that the agent generated as part of its results, you can make whatever changes are necessary (modifying JavaScript variables or even text) in the main window.
For complete details, try out the sample application listed below.
Instructions for sample application
The application first opens up a page that displays several fields and information. This page (that is really a simple Web form) and the "ProcessData" agent are the two workhorses of the example.
A user fills in the fields on the form and then clicks a button to perform an external operation. The
To continue reading for free, register below or login
To read more you must become a member of SearchDomino.com
');
// -->

external operation is launched by calling a LotusScript agent to perform some task (in this example taking two fields passed on the query string and performing a simple mathematical operation based on a third parameter passed) and then return results into an iFrame on the form.
The sample application uses one page and one agent. To run the example, create a Notes database on a Domino server capable of running Web applications. Create a page (the page name is not important) and set the page's "Web Access" content type to HTML. Paste the code listed below in that page.
Page content
Next, create an agent in the application with the name "ProcessData," specify that the agent is a LotusScript agent and then paste the code below into the agent's "Declarations" section.
Agent content
From a Web browser, open the page you created and enter two values into the first two fields. Select an operation, and then click "Run" to launch the agent.
That's it. This is a very simple example but, by extension, the capabilities of using the method described here are limited only to your imagination.
Have fun.
MEMBER FEEDBACK TO THIS TIP
Thanks for your tip. I have actually used the method you speak of in your tip also, but I have found the ActiveX method to be advantageous in certain cases. The iFrame method, although supporting most new browsers, is asynchronous. As Amigoni had commented in my tip, Run a Web agent on any JavaScript event, many users have used setTimeouts to circumvent some of the issues. I used the agent to write back script, similar to what you are doing, but the asynchronous behavior can cause trouble.
Using the iFrame method you discuss, I implemented a document locking on Domino 6 (through the use of the onunload method). When using iFrames, the agent wouldn't always run. If I forced a JavaScript alert (simply saying "The browser is now closing..."), I could almost always guarantee it, but some users on dial-up connections still had difficulty. Changing to the ActiveX method allowed for the agent to run successfully every time, without the need for the JavaScript alert. Also, a few people have commented that they enjoy the ability to send multiple requests to the server at a time, and to do this using iFrames would require many hidden iFrames as a workaround.
But, you have a point. My solution was Internet Explorer specific. After I saw your tip, I decided to spend some time to research a cross-browser method that was synchronous. I came up with one, and submitted it back to SearchDomino. Check back to the ActiveX method to make an implementation of the synchronous method cross-browser compatible (tested on Netscape 6+, Internet Exploere 5+, Mac Safari and Firefox). For those of you who followed my previous tip, there are only minor modifications to make it cross-browser friendly.
Note: If users choose to use the iFrame method, however, I suggest adding iLayer tags to support legacy Netscape 4.x browsers...
Note: The ActiveX solution does not work on Netscape 4.x, so Michael's tip should always be used if supporting that specific browser is critical.
Luke L.
Do you have comments on this tip? Let us know.