如何加载嵌入电子应用程序的js?喜欢twitter embbed

时间:2017-06-12 11:59:12

标签: electron

当我尝试加载twitter js嵌入到我的电子应用程序时,所有文本都出现但没有加载CSS。为什么会发生这种情况?加载js嵌入的最佳方法是什么?

我刚用twitter嵌入
例如: -

    var twitterEmbed = "<blockquote class="twitter-tweet" data-lang="en"><p lang="en" dir="ltr">Members of the UK Parliament openly condemn US <a href="//twitter.com/hashtag/Trump?src=hash">#Trump</a> regime. <a href="//twitter.com/hashtag/BDStheUS?src=hash">#BDStheUS</a> <a href="t.co/yY5lr3k8tl">pic.twitter.com/yY5lr3k8tl</a></p>&mdash; Anonymous  (@YourAnonCentral) <a href="//twitter.com/YourAnonCentral/status/826556764753625088">January 31, 2017</a></blockquote>
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>" 

我正在使用react.js

    <div dangerouslySetInnerHTML={{ __html: twitterEmbed }} />

1 个答案:

答案 0 :(得分:1)

The path to the script is not valid //platform.twitter.com/widgets.js is not explicit in electron even though it is valid browsers simply add https: to it.

<blockquote class="twitter-tweet" data-lang="en"><p lang="en" dir="ltr">Members of the UK Parliament openly condemn US <a href="//twitter.com/hashtag/Trump?src=hash">#Trump</a> regime. <a href="//twitter.com/hashtag/BDStheUS?src=hash">#BDStheUS</a> <a href="t.co/yY5lr3k8tl">pic.twitter.com/yY5lr3k8tl</a></p>&mdash; Anonymous  (@YourAnonCentral) <a href="//twitter.com/YourAnonCentral/status/826556764753625088">January 31, 2017</a></blockquote>
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>

Also in case of React you probably need to load the script function once the component is mounted

componentDidMount: function() {
  twttr.widgets.load()
}

Answer

If you inject an embed script on flow, it won't be able to load it. Because the react load content based on render(), so you can load embed in componentDidMount().