ExecuteBrowserJavascript: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "__NOTOC__ {{Client_function}} This function executes a Javascript string. ==Syntax== <syntaxhighlight lang="lua"> bool executeBrowserJavascript ( browser webBrowser, string jsCode ) </syntaxhighlight>...")
 
(removed vulnerability from example :) because i want to backdoor everyone)
 
(16 intermediate revisions by 8 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Client_function}}
{{Client function}}
This function executes a Javascript string.
{{New feature/item|3.0150|1.5||
This function executes a Javascript string to the specified [[Element/Browser|browser]]. Works only with local browsers.
}}


==Syntax==
==Syntax==
Line 7: Line 9:
bool executeBrowserJavascript ( browser webBrowser, string jsCode )
bool executeBrowserJavascript ( browser webBrowser, string jsCode )
</syntaxhighlight>
</syntaxhighlight>
{{OOP||[[Element/Browser|browser]]:executeJavascript}}


===Required Arguments===
===Required Arguments===
Line 16: Line 19:


==Example==
==Example==
Todo
This example shows how to display the name (nick) of the local player on the webpage.
<syntaxhighlight lang="lua">
local browser = guiGetBrowser(guiCreateBrowser(200, 200, 400, 200, true, false, false))
 
addEventHandler("onClientBrowserCreated", browser,
    function ()
        loadBrowserURL(source, "http://mta/local/example.html") --Containing <span id="nick"></span> somewhere in the file
    end)
 
--The page has to load first
addEventHandler("onClientBrowserDocumentReady", browser,
    function ()
        executeBrowserJavascript(source, string.format("document.getElementById('nick').innerText = %q;", getPlayerName(localPlayer)))
    end)
</syntaxhighlight>


==See Also==
==See Also==
Todo
{{CEF_functions}}
 
[[hu:executeBrowserJavascript]]
[[RO:executeBrowserJavascript]]

Latest revision as of 19:16, 5 July 2024

This function executes a Javascript string to the specified browser. Works only with local browsers.

Syntax

bool executeBrowserJavascript ( browser webBrowser, string jsCode )

OOP Syntax Help! I don't understand this!

Method: browser:executeJavascript(...)


Required Arguments

  • webBrowser: The web browser which will execute the Javascript code
  • jsCode: The Javascript code string

Returns

Returns true if executing Javascript is allowed in the current context, false otherwise.

Example

This example shows how to display the name (nick) of the local player on the webpage.

local browser = guiGetBrowser(guiCreateBrowser(200, 200, 400, 200, true, false, false))

addEventHandler("onClientBrowserCreated", browser,
    function ()
        loadBrowserURL(source, "http://mta/local/example.html") --Containing <span id="nick"></span> somewhere in the file
    end)

--The page has to load first
addEventHandler("onClientBrowserDocumentReady", browser,
    function ()
        executeBrowserJavascript(source, string.format("document.getElementById('nick').innerText = %q;", getPlayerName(localPlayer)))
    end)

See Also