Reputation: 1865
When I tried to load twitter js embed to my electron app, all the text came but no CSS got loaded. Why is it happening and what is the best way to load js embed?
I just used twitter embed
Eg:-
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>"
I'm using react.js so
<div dangerouslySetInnerHTML={{ __html: twitterEmbed }} />
Upvotes: 0
Views: 210
Reputation: 4501
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().
Upvotes: 1