推文按钮 - 隐藏零计数
我有兴趣向我的一些网站添加 Twitter 最近发布的官方 Tweet 按钮。
对于那些不知道的人来说,推文按钮是一个简单的 JS,您可以将其放入页面中,它允许您的用户轻松地发布有关相关页面的推文,就像 Facebook 的“分享”按钮一样。
有 3 种不同的样式可供选择:
水平计数按钮是我想放在页面上的按钮。我的问题是,大约一半的页面计数可能为零,在这种情况下我宁愿不显示计数。例如,Facebook 分享按钮可以很好地处理这种特殊情况 - 如果有 > 0 分享,则显示计数。否则计数将保持隐藏状态。
我浏览了 twitter 文档,似乎找不到在 JS 参数中指定这一点的方法。
我还花了一些时间尝试通过 jquery 捕获计数并将其隐藏,但很快遇到了跨域权限问题 -
console.log($('.twitter-share-button').contents().html());
由于从 platform0 加载 iframe,返回
。Permission returned
错误.twitter.com
有没有人找到一种成功的方法来让此按钮有条件地显示如上所述的推文计数?
I'm interested in adding to some of my sites the official Tweet button which Twitter have recently released.
For those unaware, the tweet button is a simple bit of JS which you can drop in to a page and it allows your users to easily tweet about the page in question, much like the facebok "share" button.
There are 3 different styles available:
The horizontal count button is the one I'd like to put on my pages. My problem is that roughly half of my pages are likely to have a zero count, and I'd rather not show the count when this is the case. The facebook share button, for example, handles this particular situation well - if there are > 0 shares, then it shows the count. Otherwise the count stays hidden.
I've gone through the twitter docs, and can't seem to find a way of specifying this in the JS parameters.
I also spent some time trying to capture the count via jquery and hide it, but quickly ran in to cross-domain permission issues -
console.log($('.twitter-share-button').contents().html());
returns a Permission denied
error due to the iframe being loaded from platform0.twitter.com
.
Has anyone yet found a successful way to get this button to conditionally show the tweet counts as described above?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这不是最优雅的解决方案,但您始终可以错开不同按钮类型的释放。
例如,首先显示“无计数”按钮,然后显示“水平计数”,例如从发布日期起一周。 (我假设您正在运行某种类型的博客)
同样,这不是很好,但它部分解决了您的问题 - 您将更少地显示“零推文”按钮。
问候
卢克
Not the most elegant solution, but you could always stagger the release of the different button types.
Eg, show the 'no count' button initially, then display the 'horiztonal count' say, a week from the publication date. (i'm making the assumption you're running some type of blog)
Again, not great, but it partially solves your problem - you'll display the 'zero tweets' button less often.
Regards
Luke
后来谷歌搜索,发现http://ottopress. com/2010/twitters-new-tweet-button-and-the-count-api/ 讨论如何使用 count api
http://urls.api.twitter.com/1/ urls/count.json?url=URL-TO-GET-COUNT-FOR
。A google search later, found http://ottopress.com/2010/twitters-new-tweet-button-and-the-count-api/ which talks about how to use the count api
http://urls.api.twitter.com/1/urls/count.json?url=URL-TO-GET-COUNT-FOR
.