JS: Difference between revisions

From GiderosMobile
added example from E1e5en
m Text replacement - "</source>" to "</syntaxhighlight>"
 
(2 intermediate revisions by 2 users not shown)
Line 9: Line 9:
=== Example ===
=== Example ===
'''Get/Set'''
'''Get/Set'''
<source lang="lua">
<syntaxhighlight lang="lua">
-- sets a variable and a listener
-- sets a variable and a listener
JS.eval([[
JS.eval([[
document.isPause = false;
document.isPause = false;
document.addEventListener('visibilitychange', function() {
document.addEventListener('visibilitychange', function() {
if (document.visibilityState == 'hidden') {
if (document.visibilityState == 'hidden')
document.isPause = true
document.isPause = true;
};
else
document.isPause = false;
});
});
]])
]])
Line 22: Line 23:
-- gets the value of a variable
-- gets the value of a variable
print(JS.eval("document.isPause"))
print(JS.eval("document.isPause"))
</source>
</syntaxhighlight>


{|-
{|-

Latest revision as of 13:30, 13 July 2023

Supported platforms:
Available since: 2019.1

Description

Runs JavaScript code.

Example

Get/Set

-- sets a variable and a listener
JS.eval([[
	document.isPause = false;
	document.addEventListener('visibilitychange', function() {
		if (document.visibilityState == 'hidden')
			document.isPause = true;
		else
			document.isPause = false;
	});
]])
 
-- gets the value of a variable
print(JS.eval("document.isPause"))

Methods

JS.eval executes the given JavaScript code

Events

Constants