使用jQuery将Tweet按钮加载到Container中 [英] Load Tweet Button with jQuery into Container

查看:78
本文介绍了使用jQuery将Tweet按钮加载到Container中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Tweet按钮出现问题。以下是Twitter提供的代码:

I'm having problems with the Tweet button. Here is the code that Twitter provides:

    <a href="https://twitter.com/share" class="twitter-share-button">Tweet</a>
    <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>

我正在将其加载到弹出我的页面的模态中。它第一次加载时效果很好,但如果有人关闭模态并重新打开它,它就不再加载按钮了。

I'm loading this into a modal that pops up over my page. It works great the first time it's loaded, but if someone closes the modal and reopens it, it doesn't load the button anymore.

推荐答案

你可以尝试添加Twitter的widgets.js作为常规脚本包含在你的< head> 中,然后一旦你渲染了你的模态你可以调用

You could try adding Twitter's widgets.js as a regular script include within your <head>, and then once you have rendered your modal you can call

twttr.widgets.load();

应该刷新它找到的任何推特按钮。

which should refresh any twitter buttons it finds.

这意味着您不需要提供的代码段中的块,您的推文按钮只是表格

This means you don't need the block from the supplied snippet, your tweet buttons are just of the form

<a href="https://twitter.com/share" class="twitter-share-button">Tweet</a>

这篇关于使用jQuery将Tweet按钮加载到Container中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆