Client-side 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
You can also return values from the JavaScript code. The returned value will be available in the Python code.
from abstra.forms import execute_js
referrer = execute_js("document.referrer")
print(f"I see you are coming from {referrer}")