Setting Handlers for VMRC Events
When there is a change in the state of a VMRC session, the VMRC browser plug-in generates events using the VMRC API. Events generated include changes in connection state, changes in screen size on the target virtual machine, or events generated in response to messages from the VMRC plug-in. See Handling VMRC Events.
To use the VMRC browser plug-in, your Web application must set up handlers for the VMRC events. You must bind the events to JavaScript handler methods in your Web application. The VMRC API provides different binding mechanisms for each supported Web browser.
Setting Handlers in Internet Explorer
In Internet Explorer, handler methods are bound using the attachEvent() method. You set the handler method by calling attachEvent() and passing as parameters the event name as a string, and a pointer to the JavaScript handler method.
For example, to set a handler method for the onConnectionStateChange event, you must call attachEvent() as follows:
vmrc.attachEvent(“onConnectionStateChange”, onConnectionStateChangeHandler);
The first parameter to attachEvent() is the event name that is defined in the VMRC API. The second parameter is the JavaScript handler method that you define.
Setting Handlers in Firefox or Chrome
In Firefox and Chrome, each event corresponds to a property of the VMRC plug-in object instance. You bind a handler method to a VMRC event by setting the corresponding event property value to the handler method.
For example, to set a handler method for the onConnectionStateChange event, you must set the VMRC object instance’s onConnectionStateChange property as follows:
vmrc[“onConnectionStateChange”] = onConnectionStateChangeHandler;
Abstracting Event Handler Setup
The VMRC SDK contains sample code that shows how to abstract the setting of event handlers into a single function that can be used with all supported browsers. See the attachEventHandler() method in the sample file vmrc-embed-example.js in the VMRC SDK binaries.