Gop*_*ops 18 javascript jquery facebook-like facebook-social-plugins
我有一个带有重写网址的动态页面.我想在其中添加一个facebook分享按钮.因此用户点击分享按钮即可共享页面.但facebook分享开发者页面要求提供特定网址.不确定如何共享动态生成的URL.
这里我发现一些代码来捕获网址.但我不知道,如何将其包含在Facebook代码中.
jQuery(document).ready(function() {
var href = jQuery(location).attr('href');
var url = jQuery(this).attr('title');
jQuery('#current_title').html(href);
jQuery('#current_url').html(url);
});
Run Code Online (Sandbox Code Playgroud)
HTML共享按钮的HTML部分
<div class="fb-share-button" data-href="http://developers.facebook.com/docs/plugins/" data-type="button"></div>
Run Code Online (Sandbox Code Playgroud)
请帮助
非常感谢
wen*_*ntz 25
这对我有用:
<script language="javascript">
function fbshareCurrentPage()
{window.open("https://www.facebook.com/sharer/sharer.php?u="+encodeURIComponent(window.location.href)+"&t="+document.title, '',
'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');
return false; }
</script>
Run Code Online (Sandbox Code Playgroud)
然后使用链接调用代码:
<a href="javascript:fbshareCurrentPage()" target="_blank" alt="Share on Facebook">Facebook</a>
Run Code Online (Sandbox Code Playgroud)
如果您希望它是直接链接而不是在窗口中打开,请在函数中使用:
window.location.href="https://www.facebook.com/sharer/sharer.php?u="+encodeURIComponent(window.location.href)+"&t="+document.title;
Run Code Online (Sandbox Code Playgroud)
可能的jquery解决方案:
<a class="fbsharelink" data-shareurl="YOURLINK">Facebook</a>
$('.fbsharelink').click( function()
{
var shareurl = $(this).data('shareurl');
window.open('https://www.facebook.com/sharer/sharer.php?u='+escape(shareurl)+'&t='+document.title, '',
'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');
return false;
});
Run Code Online (Sandbox Code Playgroud)
小智 10
请勿在"删除现有链接"(https://developers.facebook.com/docs/plugins/)中输入任何内容,并像平常一样在页面中包含代码.
喜欢或分享按钮会选择当前页面的链接