当我尝试加载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>— 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 }} />
答案 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>— 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().