API Functions

Function Description
NxCreateDui("https://url/") Create a DUI window from a URL. The first DUI gets index 0, the next one index 1, etc.
NxToggleDui(index) Show or hide a DUI window.
NxDestroyDui(index) Destroy a DUI window.
NxSendDuiMessage(index, '{"action":"hide"}') Send a JSON message to the DUI. Captured with window.addEventListener("message").
NxRegisterDUICallback(index, "CallbackName", function(data) end) Registers a callback function that listens for messages sent from the DUI (browser side) to the Lua backend.
NxIsKeyJustPressed(VK) Returns true when the given key is just pressed.
NxIsKeyPressed(VK) Returns true while the given key is held down.

Code Examples

Required structure server side (files.json) :

JSON

{
    "files": [
        "index.html",
        "menu.js",
        "style/logo.png",
        "style/style.css"
    ]
}

Simple Lua NUI example :

Lua

local index = 0

-- Create a DUI window
NxCreateDui("https://yourduiurl/")

Citizen.Wait(300)

-- Register a Callback
NxRegisterDUICallback(index, "CallBackName", function(data)
    print("Callback executed successfully. Received data:", data)
end)

local VK_F5 = 0x74
local VK_F6 = 0x75
local VK_F7 = 0x76

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)

        -- Show / Hide
        if NxIsKeyJustPressed(VK_F5) then
            NxToggleDui(index)
        end

        -- Destroy
        if NxIsKeyJustPressed(VK_F6) then
            NxDestroyDui(index)
        end

        -- Send Message
        if NxIsKeyJustPressed(VK_F7) then
            NxSendDuiMessage(index, '{"action":"hide"}')
        end
    end
end)

JavaScript - Receiving DUI Messages :

JavaScript

window.addEventListener("message", (event) => {
    const data = event.data;
    if (data.action === "hide") {
    document.body.style.display = "none";
    }
});

JavaScript - Call Lua Callbacks :

JavaScript

fetch(`https://nxapi/CallBackName`, {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json; charset=UTF-8',
    },
    body: JSON.stringify({
        callback: 'success'
    })
}).then(resp => resp.json()).then(resp => console.log(resp));

Refer to the Microsoft Virtual-Key Codes documentation for all keycode values.