Javascript events with csXImage running in Internet Explorer.

In Javascript, when an ActiveX control exports events, the event must be declared in a <script> block. This block can be anywhere in the page but in our example we show it immediately after the control is declared.

Example:

<script language="JavaScript" for="csxi" event="onMouseDown(Button, ShiftState, X, Y);">
csXIMouseDown(Button, ShiftState, X, Y);
</script>

In this example the csXImage object has already been declared with the name "csxi" and this name must also be used in the FOR attribute. The event and its parameters is specified in the EVENT attribute. For details of csXImage event names and parameters, refer to the instructions. The code that is executed when the event fires is inside the <script> block and in this case it is a function, which will have been defined in the header of the script.

We have a downloadable example which is aimed for use with the trial version of csXImage - mouseevents.zip. This is available to view as a live demo - here. Note that the online demo uses the unsigned trial version of csXImage so it will generate a browser security warning unless you have already downloaded and installed the csXImage trial.

Not all events have parameters, and one such event that is often used in Javascript applications is OnAcquire, which is used when scanning and producing multi-page TIFF or PDF documents.

The Javascript onLoad and onUnload events

When a web page loads, the Javascript onLoad event fires and this can be used inside the <body> tag to run some initialisation code. The mouse event downloadable demo from above uses this event to call a function which sets the initial button states.

Example:

<body onload="Initialisation();">

The onUnload event fires when the user navigates away from the web page by following a link. A time to use this event is when the csXImage built in selection methods are used, MouseSelectRectangle and MouseSelectEllipse. This is unrelated to the above downloadable example. When a selection is being made, csXImage is waiting for user input and if the user does not complete the selection the CancelSelection command must be called. This should be added to the onUnload event handler if a selection is used on the page.

Example:

<body onunload="csxi.CancelSelection();">

It is possible to call both events in the <body> tag so that some code runs when the page loads and some when it closes.