Trigger event or method via javascript

Hi, is there a way to call a event defined or a method via javascript? I’m using the 2020r2.1 version of xojo and I tried to use triggerServerEvent method and it’s not working.

Defined where?

In Web 2.0 that method is now a member of the XojoControl (and/or XojoVisualControl) JavaScript class. You’d need to first get a control instance from the XojoWeb object, then call the triggerServerEvent method of that object. Something like this, in Xojo, should work:

ExecuteJavascript( "XojoWeb.getNamedControl('" + me.ControlID + "').triggerServerEvent('eventName', ['paremeters'], true);" )

But in order to receive the event, your target must be a WebSDK component that has the capacity to handle the event or a built-in component whose event name strings and parameter values you know.

For more information about the Web 2.0 WebSDK, be sure to read the documentation. You’ll find the PDF in your Xojo installation under /Extras/WebSDK along with some examples.

1 Like