Browser::execute: Difference between revisions

From RAGE Multiplayer Wiki
m (Removed typing example, updated page.)
 
Line 1: Line 1:
This function used for call JavaScript code in created browser.
{{ClientsideJsFunction}}
Calls JavaScript code inside the browser.


{{JSContainer|
==Syntax==
==Syntax==
<syntaxhighlight lang="javascript">
<pre>
browser.execute(String executedCode);
browser.execute(executedCode);
</syntaxhighlight>  
</pre>  
===Required Arguments===
===Required Arguments===
*'''executedCode:''' JavaScript code what will be executed in browser.
*'''executedCode:''' JavaScript code to be executed in browser.


==Example==
==Example==
That's example made nothing useful:
Create a popup alert in the browser
<syntaxhighlight lang="javascript">
{{ClientsideCode|
<pre>
browser.execute(`alert(\`It's a test.\`);`);
browser.execute(`alert(\`It's a test.\`);`);
</syntaxhighlight>
</pre>
 
}}
Get Chatbox status by executing code / check if open:
}}
<syntaxhighlight lang="javascript">
var isChatOpen = toggle;
 
mp.events.add('render', () => {
if (mp.game.controls.isDisabledControlJustReleased(0, 245)) {
    if (isChatOpen)
        return;
    mp.gui.execute("const _enableChatInput = enableChatInput;enableChatInput = (enable) => { mp.trigger('chatEnabled', enable); _enableChatInput(enable) };");
    }
}
</syntaxhighlight>


==See Also==
==See Also==
{{Browser_definition_c}}
{{Browser_definition_c}}
[[Category:Clientside API]]

Latest revision as of 22:33, 20 April 2020

Client-Side
Function

 JavaScript



Calls JavaScript code inside the browser.

JavaScript Syntax

Syntax

browser.execute(executedCode);

Required Arguments

  • executedCode: JavaScript code to be executed in browser.

Example

Create a popup alert in the browser

Client-Side
browser.execute(`alert(\`It's a test.\`);`);


See Also