fivem trigger javascript function

JavaScript
// JS
SendNuiMessage(JSON.stringify({
    type: 'open'
}))
-- Lua
SendNUIMessage({
    type = 'open'
})
// browser side
window.addEventListener('message', (event) => {
    if (event.data.type === 'open') {
        doOpen();
    }
});
// C#, assumes Newtonsoft.Json PCL version is referenced
SendNuiMessage(JsonConvert.SerializeObject(new
{
    type = "open"
}));

Source

Also in JavaScript: