Difference between revisions of "JS"

From GiderosMobile
(removed language stuff)
(added example from E1e5en)
Line 6: Line 6:
 
=== Description ===
 
=== Description ===
 
Runs JavaScript code.
 
Runs JavaScript code.
 +
 +
=== Example ===
 +
'''Get/Set'''
 +
<source lang="lua">
 +
-- sets a variable and a listener
 +
JS.eval([[
 +
document.isPause = false;
 +
document.addEventListener('visibilitychange', function() {
 +
if (document.visibilityState == 'hidden') {
 +
document.isPause = true
 +
};
 +
});
 +
]])
 +
 +
-- gets the value of a variable
 +
print(JS.eval("document.isPause"))
 +
</source>
  
 
{|-
 
{|-

Revision as of 07:12, 8 September 2021

Supported platforms: Platform html5.png
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
		};
	});
]])
 
-- gets the value of a variable
print(JS.eval("document.isPause"))

Methods

JS.eval executes the given JavaScript code

Events

Constants