Skip to main content

Execute JavaScript

Use execute_js to execute JavaScript on the user's browser.

from abstra.forms import execute_js

execute_js("console.log('Hello world!')")

Context

The context parameter can be used to pass variables to the JavaScript code.

from abstra.forms import execute_js

a = 2 + 3

execute_js("console.log('Result: ' + $context.result)", context={"result": a})
# Open your console to check the result!

Returning values

The return value of the JavaScript function can be retrieved using the return_value parameter.

from abstra.forms import execute_js

referrer = execute_js("document.referrer")

print(f"I see you are coming from {referrer}")