简体   繁体   English

我可以在iFrame或类似Python的小部件上调用JavaScript函数吗?

[英]Can I call a JavaScript function on an iFrame or similar widget from Python?

I am trying to mix Python code with D3 vizualizations. 我正在尝试将Python代码与D3 vizualizations混合使用。 Right now I have a bunch of D3 vizualizations and JavaScript functions. 现在,我有很多D3 vizualization和JavaScript函数。 I have a couple different ways of embedding the D3, but what I want is to call a function that affects the vizualization AFTER I create it. 我有几种不同的嵌入D3的方法,但是我想要的是在创建D3之后调用一个会影响vizualization的函数。

For example: 例如:

createD3Stuff()
for i in [0,1,2,3]:
    executeFunction(i)

Where createD3Stuff() generates the vizualization, and executeFunction does something on that vizualization, like creates an element with id=i. 在createD3Stuff()生成vizualization的位置,executeFunction在该vizualization上执行一些操作,例如创建一个id = i的元素。

Is this possible? 这可能吗? How can I do it? 我该怎么做?

Background information: I am using Jupyter Notebooks, but if there is some other way to get this to work I can switch. 背景信息:我正在使用Jupyter笔记本电脑,但是如果还有其他方法可以使它工作,我可以进行切换。 I know how to do all the d3 and javascript stuff, it is just getting the python and javascript to interact that is giving me trouble. 我知道怎么做所有的d3和javascript东西,仅仅是让python和javascript交互给我带来麻烦。

Of course you can. 当然可以。

Just try this: 尝试一下:

from IPython.display import HTML
HTML("<script>alert('hello world')</script>")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM