Jump to content

Return function in html page or sending variables from Lua


draobrehtom

Recommended Posts

The Main Question: How I can send data to HTML page (CEF browser) from Lua code?

I know has executeBrowserJavascript, but I don't know how exactly I can use it, I try define variables like a

executeBrowserJavascript(theBrowser, "var example = 5") 

And use it in HTML code

mta.triggerEvent("cmsg", example) 

but nothing. Or:

var test = mta.triggerEvent("cmsg", "hello mta") 
mta.triggerEvent("cmsg", test) 

And:

function cmsg(msg) 
    outputChatBox(tostring(msg)) 
    return 5 
end 
addEvent("cmsg", true) 
addEventHandler("cmsg", root, cmsg) 

But variable test is "unsupported type" (showing outputChatBox)

Can you help me?

Link to comment

I found a one way with using Using innerHTML. Here is my code:

Lua:

  
function cmsg(msg) 
    executeBrowserJavascript(theBrowser, 'document.getElementById("demo").innerHTML = "' .. msg .. '"') 
end 
addEvent("cmsg", true) 
addEventHandler("cmsg", root, cmsg) 
  

HTML:

  
<!DOCTYPE html> 
<html> 
    <body> 
        <p id="demo"></p> 
        <script> 
            mta.triggerEvent("cmsg", "Hello MTA") 
        </script> 
    </body> 
</html>  
  
  

Link to comment
  • 8 years later...

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...