【问题标题】:Infogram embed code not rendering in ReactInfogram 嵌入代码未在 React 中呈现
【发布时间】:2019-07-30 04:43:14
【问题描述】:

我有以下来自 infogram 的嵌入代码,它没有在我的 react 应用程序上呈现。

code looks as below:
<div class="infogram-embed" data-id="861ca70e-552c-4a4f-960a-4c7e7ff62881" data-type="interactive" data-title="Step by Step Charts"></div><script>!function(e,t,s,i){var n="InfogramEmbeds",o=e.getElementsByTagName("script")[0],d=/^http:/.test(e.location)?"http:":"https:";if(/^\/{2}/.test(i)&&(i=d+i),window[n]&&window[n].initialized)window[n].process&&window[n].process();else if(!e.getElementById(s)){var r=e.createElement("script");r.async=1,r.id=s,r.src=i,o.parentNode.insertBefore(r,o)}}(document,0,"infogram-async","https://e.infogram.com/js/dist/embed-loader-min.js");</script><div style="padding:8px 0;font-family:Arial!important;font-size:13px!important;line-height:15px!important;text-align:center;border-top:1px solid #dadada;margin:0 30px"><a href="https://infogram.com/861ca70e-552c-4a4f-960a-4c7e7ff62881" style="color:#989898!important;text-decoration:none!important;" target="_blank">Step by Step Charts</a><br><a href="https://infogram.com" style="color:#989898!important;text-decoration:none!important;" target="_blank" rel="nofollow">Infogram</a></div>

我正在使用一个 html 解析库进行反应,它在所有其他情况下都可以正常工作。

知道为什么这不起作用吗?

谢谢

【问题讨论】:

    标签: javascript html reactjs html-parsing


    【解决方案1】:

    不确定这是否有帮助,这是我如何使它与 React 一起工作的 https://jsfiddle.net/wonderwhy_er/4dt28xzL/6/

    或代码 在 HTML 中

    <script>!function(e,t,s,i){var n='InfogramEmbeds',o=e.getElementsByTagName('script')[0],d=/^http:/.test(e.location)?'http:':'https:';if(/^\/{2}/.test(i)&&(i=d+i),window[n]&&window[n].initialized)window[n].process&&window[n].process();else if(!e.getElementById(s)){var r=e.createElement('script');r.async=1,r.id=s,r.src=i,o.parentNode.insertBefore(r,o)}}(document,0,"infogram-async","https://e.infogram.com/js/dist/embed-loader-min.js");</script>
    
    
    <div id="app"></div>
    

    在 JS 中

    class App extends React.Component {
      constructor(props) {
        super(props)
      }
    
      render() {
        return (
          <div>
            <div class="infogram-embed" data-id="861ca70e-552c-4a4f-960a-4c7e7ff62881" data-type="interactive" data-title="Step by Step Charts">
            </div>
          </div>
        )
      }
    }
    
    ReactDOM.render(<App />, document.querySelector("#app"))
    

    我把脚本部分移走了,它只是从 Infogram 请求一个加载器,你不需要在 React 渲染中做它,所以我只是把它移到页面的标题或其他地方。

    我删除的嵌入末尾还有其他内容,并且可以正常工作。检查链接。

    【讨论】:

    • 我正在做你所做的事情,而不是为我工作!是否可能从 localhost 无法正常工作?
    • 嗯,好吧,我猜想控制 dom 渲染发生方式的此类嵌入和框架(例如 React)并不总是按预期工作如果您有无法正常工作的示例,您可以尝试联系 Infogram 支持
    猜你喜欢
    • 2020-05-15
    • 1970-01-01
    • 2021-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多