Skip to content

Client Side Events

Rocky Bevins edited this page Jun 13, 2019 · 4 revisions

You can write client side event handlers by setting the 'evt' (event) property on any outgoing message object and adding a handler to your client script.

Example

Somewhere server-side we send a client a message with a defined evt property. In this case 'showAlert'.

World.msgPlayer(s, {
    msg: '',
    evt: 'showAlert',
    data: {alert: 'Hello World'}
});

Client side handler:

document.addEventListener('showAlert', function(e) {
    e.preventDefault();
		
    alert(e.command.data.alert);
}, false);