Jump to content

Recommended Posts

Hello I have an issue when I trigger an event that call a function using onClientBrowserDocumentReady, i don't know what is the issue...

This is my code:

The issue is...  onClientBrowserDocumentReady doesn't found the browser and it can't in into the event.

the executeBrowserJavascript doesn't work


event = {add = addEventHandler, load = addEvent, execute = triggerServerEvent}

local WINDOW_WIDTH, WINDOW_HEIGHT = guiGetScreenSize()
local CEF = nil
local browser = nil
function deleteWebPage()
    if isElement(CEF) then
function createWebPage()
    page = "http://mta/player/html/login.html"
    CEF =
        guiCreateBrowser(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, true, false, false)
    browser = guiGetBrowser(CEF)
    addEventHandler("onClientBrowserCreated", browser, function()
        loadBrowserURL(source, page)
function sendErrorLabel(error)        
    addEventHandler("onClientBrowserDocumentReady", browser, function()        
                                 "document.querySelector('.error:nth-child(5)').innerHTML = '" ..
                                     error .. "'");
                                 "document.querySelector('.error:nth-child(5)').style = 'display: initial; top: 90%; left:40.5%'");
event.load('login-data:send', true)
event.add('login-data:send', root, function(user, password)
    event.execute('login-menu:execute', resourceRoot, user, password)
end, true)
event.load("onClientPlayerLogout", true)
event.add("onClientPlayerLogout", root, function() createWebPage() end)
event.load("show-label:error", true)
event.add("show-label:error", root, function(error) sendErrorLabel(error) end)
event.load('login-menu:remove', true)
event.add('login-menu:remove', root, function() deleteWebPage() end)
event.add("onClientResourceStart", resourceRoot, function() createWebPage() end)



Edited by KyonaxDEV
Link to comment

Okay... the solution was very simple, only make the CEF, page and browser global variables ...like this


event = {add = addEventHandler, load = addEvent, execute = triggerServerEvent}
local WINDOW_WIDTH, WINDOW_HEIGHT = guiGetScreenSize()
-- HTML Web Page Creation
page = "http://mta/player/html/login.html"
CEF = guiCreateBrowser(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, true, false, false)
local browser = guiGetBrowser(CEF)


Then delete the onClientBrowserDocumentReady  event, and that's it


function sendErrorLabel(error)
                             "document.querySelector('.error:nth-child(5)').innerHTML = '" ..
                                 error .. "'");
                             "document.querySelector('.error:nth-child(5)').style = 'display: initial; top: 90%; left:40.5%'");

All the code works fine

Edited by KyonaxDEV
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...