ExecuteBrowserJavascript: Difference between revisions
Jump to navigation
Jump to search
m (fix oops) |
(Added example) |
||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
{{Client function}} | {{Client function}} | ||
{{New feature/item|3.0150|1.5|| | {{New feature/item|3.0150|1.5|| | ||
This function executes a Javascript string to the specified [[Element/Browser|browser]]. | This function executes a Javascript string to the specified [[Element/Browser|browser]]. Works only with local browsers. | ||
}} | }} | ||
Line 20: | Line 19: | ||
==Example== | ==Example== | ||
This example shows how to display the name (nick) of the local player on the webpage. | |||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
-- | local browser = 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, "document.getElementById('nick').innerHTML = '" .. getPlayerName(localPlayer) .. "'"); | |||
end) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
==See Also== | ==See Also== | ||
{{CEF_functions}} | {{CEF_functions}} |
Revision as of 22:33, 15 July 2017
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 = 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, "document.getElementById('nick').innerHTML = '" .. getPlayerName(localPlayer) .. "'"); end)
See Also
- canBrowserNavigateBack
- canBrowserNavigateForward
- createBrowser
- executeBrowserJavascript
- focusBrowser
- getBrowserProperty
- getBrowserSettings
- getBrowserSource
- getBrowserTitle
- getBrowserURL
- injectBrowserMouseDown
- injectBrowserMouseMove
- injectBrowserMouseUp
- injectBrowserMouseWheel
- isBrowserDomainBlocked
- isBrowserFocused
- isBrowserLoading
- isBrowserRenderingPaused
- loadBrowserURL
- navigateBrowserBack
- navigateBrowserForward
- reloadBrowserPage
- requestBrowserDomains
- resizeBrowser
- setBrowserAjaxHandler
- setBrowserProperty
- setBrowserRenderingPaused
- setBrowserVolume
- toggleBrowserDevTools