HU/executeBrowserJavascript

From Multi Theft Auto: Wiki
Revision as of 11:02, 30 July 2018 by Surge (talk | contribs)
Jump to navigation Jump to search

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

Szintaxis

bool executeBrowserJavascript ( browser webBrowser, string jsCode )

OOP Syntax Help! I don't understand this!

Method: browser:executeJavascript(...)


Kötelező argumentumok

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

Visszaadott érték

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

Példa

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, "document.getElementById('nick').innerHTML = '" .. getPlayerName(localPlayer) .. "'");
    end)

SLásd még

Fordította

  • Surge