简体   繁体   English

推文按钮在浏览链接导轨 4 twitter 时消失

[英]Tweet button disappears on navigating through link rails 4 twitter

I have added a tweet button in my app that appears when I land on a page initially or refresh the page but doesn't display the button when I navigate through a link.我在我的应用程序中添加了一个推文按钮,当我最初登陆页面或刷新页面时会出现该按钮,但在我浏览链接时不显示该按钮。 It only displays the text written within a tag.它只显示写在标签内的文本。 I can see the difference in the two cases through inspect element.我可以通过检查元素看到两种情况的区别。

<a href="https://twitter.com/share" class="twitter-share-button" data-url="http://example.com" data-via="sometext" data-size="large">Tweet</a>
<script>!function (d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0], p = /^http:/.test(d.location) ? 'http' : 'https';
    if (!d.getElementById(id)) {
    js = d.createElement(s);
    js.id = id;
    js.src = p + '://platform.twitter.com/widgets.js';
    fjs.parentNode.insertBefore(js, fjs);
  }
}(document, 'script', 'twitter-wjs');</script>

I have copied the above code from this link https://dev.twitter.com/web/tweet-button我已经从这个链接https://dev.twitter.com/web/tweet-button复制了上面的代码

The difference in the two cases:两种情况的区别:

Case 1: When the button appears:情况一:当按钮出现时:

<iframe id="twitter-widget-0" scrolling="no" frameborder="0" allowtransparency="true" src="http://platform.twitter.com/widgets/tweet_button.7d9dd43d4f18b1bb51cc9d8f0997995e.en.html#_=1427878870272&amp;count=horizontal&amp;dnt=false&amp;id=twitter-widget-0&amp;lang=en&amp;original_referer=http%3A%2F%2Flocalhost%3A3000%2Fusers%2Fedit&amp;size=l&amp;text=Draft%20Picks&amp;url=http%3A%2F%2Fexample.com&amp;via=sometext" class="twitter-share-button twitter-tweet-button twitter-share-button twitter-count-horizontal" title="Twitter Tweet Button" data-twttr-rendered="true" style="width: 140px; height: 28px;"></iframe>
<script>!function (d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0], p = /^http:/.test(d.location) ? 'http' : 'https';
    if (!d.getElementById(id)) {
    js = d.createElement(s);
    js.id = id;
    js.src = p + '://platform.twitter.com/widgets.js';
    fjs.parentNode.insertBefore(js, fjs);
  }
}(document, 'script', 'twitter-wjs');</script>

Case 2: When the button disappears情况二:当按钮消失时

<a href="https://twitter.com/share" class="twitter-share-button" data-url="http://example.com" data-via="sometext" data-size="large">Tweet</a>
<script>!function (d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0], p = /^http:/.test(d.location) ? 'http' : 'https';
  if (!d.getElementById(id)) {
    js = d.createElement(s);
    js.id = id;
    js.src = p + '://platform.twitter.com/widgets.js';
    fjs.parentNode.insertBefore(js, fjs);
  }
}(document, 'script', 'twitter-wjs');</script>

I will be really thankful if someone figure out how is iframe displayed or removed over here or a proper solution to this.如果有人弄清楚 iframe 是如何在此处显示或删除的,或者对此有适当的解决方案,我将非常感激。 A very many thanks in advance!!非常感谢提前!

It was basically a turbolink issue.这基本上是一个turbolink问题。 My javascript was not loaded.我的 javascript 没有加载。 Those links on which I did want javascript to work I just added this line of code after link_to tag我确实希望 javascript 在其上工作的那些链接我只是在 link_to 标记之后添加了这行代码

data: {no_turbolink: true}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM