Calling a javascript function from python code?
See original GitHub issueI’m trying to embed the Ace Editor in my application. https://ace.c9.io/#nav=embedding
with the following script in head_html
, I just need to call the create_editor
and destroy_editor
functions with the appropriate strings.
Is there a way to invoke a JS function from the python backend?
<script src="/static/ace-builds/src-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>
<script>
window.all_editors = {};
function create_editor(element_id) {
var editor = ace.edit(element_id);
editor.setTheme("ace/theme/monokai");
editor.session.setMode("ace/mode/markdown");
window.all_editors[element_id] = editor;
}
function destroy_editor(element_id) {
window.all_editors[element_id].destroy();
delete window.all_editors[element_id];
}
</script>
Issue Analytics
- State:
- Created 4 years ago
- Comments:10
Top Results From Across the Web
How do I call a Javascript function from Python? - Stack Overflow
To interact with JavaScript from Python I use webkit, which is the browser renderer behind Chrome and Safari. There are ...
Read more >How to Run Javascript from Python ? - GeeksforGeeks
The js2py module provides one way for converting JS code to Python code we must use the translate_file() function for this. After the ......
Read more >Run Javascript from Python| | Js2Py - Medium
In this Blog article, we will learn how to Run Javascript commands from inside Python script. We will make use of the Js2Py...
Read more >How to Run JavaScript in Python - MakeUseOf
Declare a function using JavaScript format and enclose it in the multiline string (""" or '''). You can store it in a variable...
Read more >How To Run Javascript From Python - Detailed Guide?
To run a JavaScript function from python, create a function and assign it into a variable. Then invoke that function using the eval_js()...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So this enhancement was very simple to implementand I added it to version 0.0.8 (coming out Monday).
I added a method to the WebPage class called
run_javascript
. It accepts as an argument a string with JS code.This is the test example:
If you are building a custom element, then you can use the Vue life cycle hooks such as
mounted
.