从React组件内的iframe访问html元素

时间:2018-07-02 16:01:34

标签: reactjs iframe shopify

我有一个组件,用于渲染从API端点接收到的iframe。在此iframe中,有一个按钮,我想在其中添加OnClick侦听器并触发事件。我可以在浏览器控制台中使用Jquery访问此按钮,并执行我想要的操作,但不能在react App中执行。是否有(智能)访问/引用此按钮,然后向其添加侦听器的功能?例如ComponentDidMount()内?还是iframe中的addEventListener这个按钮?

我想做的事情是这样的:

componentDidMount = () => {
      window.addEventListener("click", this.handleFunction);
}

handleFunction = (e) => {
    console.log(e)
    window.event = e // then get the clicked button from this event
}

但是我不知道如何到达被按下的按钮元素。它在事件e

中以某种方式存在

0 个答案:

没有答案
相关问题